int main(void)
{
int num, count, total, max, min;
float average;
// initialization
count = total = 0;
max = INT_MIN;
min = INT_MAX;
printf("Enter a series of integers terminated by a 0: \n");
while(scanf(" %d", &num)!= 0)
{
count++;
total += num;
if(max < num)
max = num;
if(min > num)
min = num;
average = total / count;
printf("You have entered %d integers\n", count);
printf("The average is %f\n", average);
printf("The maximum is %d\n", max);
printf("The minimum is %d\n", min);
}
#include <stdio.h>
#include <limits.h>
int main(void)
{
int num, count, total, max, min;
float average;
// initialization
num = count = total = 0;
max = INT_MIN;
min = INT_MAX;
average = 0.;
printf("Enter a series of integers terminated by a 0: \n");
while(scanf(" %d", &num) && num != 0)
{
count++;
total += num;
if(max < num)
max = num;
if(min > num)
min = num;
average = float(total) / float(count);
}
printf("You have entered %d integers\n", count);
printf("The average is %f\n", average);
printf("The maximum is %d\n", max);
printf("The minimum is %d\n", min);
return 0;
}
Enter a series of integers terminated by a 0:
1 2 3 4 5 6 0
You have entered 6 integers
The average is 3.500000
The maximum is 6
The minimum is 1
Enter a series of integers terminated by a 0:
1
2
3
4
5
6
0
You have entered 6 integers
The average is 3.500000
The maximum is 6
The minimum is 1