-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex3.c
37 lines (31 loc) · 962 Bytes
/
ex3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Write a program that finds the smallest of several integers. Assume that the first value read specifies the number of values remaining.
#include <stdio.h>
#include <limits.h> // For INT_MAX
int main()
{
int n, value;
int smallest = INT_MAX; // Initialize smallest to the largest possible integer
// Read the number of integers to compare
printf("Enter the number of integers: ");
scanf("%d", &n);
// Loop to read the integers and find the smallest
for (int i = 0; i < n; i++)
{
printf("Enter integer #%d: ", i + 1);
scanf("%d", &value);
if (value < smallest)
{
smallest = value; // Update smallest if a smaller integer is found
}
}
// Check if any integer was entered and print the smallest
if (n > 0)
{
printf("The smallest integer is: %d\n", smallest);
}
else
{
printf("No integers were entered.\n");
}
return 0;
}