Example while loop: Average, Minimum and Maximum Calculation

Example while loop: Average, Minimum and Maximum Calculation

min, max and total, Average, calculation program in C/C++ array

#include<stdio.h>
int main()
{   int s[4],i, c,m,ll,small, sum=0;
float avg;
for(i=0;i<4;i++){
printf(“Enter array index %d value: “, i);
scanf(“%d”,(s+i));// Taking Array value Using a loop
}
m = s[0]; // seating the 1st m value
for ( c = 0 ; c < 4 ; c++ ){
if ( s[c] < m ) m = s[c];
if ( s[c] > m ) small = s[c];
sum = sum+s[c]; // Doing sum here
}
avg=(1.0*sum/4); // Sir Got interesting thing with 1.0
printf(“\nSmall value is: %d”, m);
printf(“\nBig value is: %d. \n\n————***********—————“, small);
printf(“\nTotal : %d “, sum);
printf(“\nAvg: %f \n\n”,avg);
return 0;
}

Leave a reply