What is wrong with this code? program that outputs minimum, maximum and
average of integers in C using Array
/*C program that outputs minimum, maximum and average of integers*/
#include <stdio.h>
#include <conio.h>
void main()
{
int i,a[5],min,max;
float avg;
printf("\n Enter any number : ");
scanf("%d",&a[0]);
max=a[0];
min=a[0];
avg=0;
for(i=1; i++;)
{
printf("\n Enter any0 Number : ");
scanf("%d",&a[i]);
if(a[i]>max)
{
max=a[i];
}
else
{
min=a[i];
}
avg=avg+a[i];
}
avg=avg/5;
printf("\n The minimum number is %d",min);
printf("\n The maximum number is %d",max);
printf("\n The average is %f",avg);
getch();
}
It should ask the user 5 times but it doesn't :( ? and the output should
be like.. this
Output:
Enter number: 4 Enter number: 6 Enter number: 7 Enter number: 20 Enter
number: 1
Minimum is 1. Maximum is 20. Average is 7.6.
How can I fix this?
No comments:
Post a Comment