friends i am a computer science student and my lecturer given me a assignment to write a program to input 20 numbers into array and count the total and average of the marks.so i have written the above code as answer.now when i check the answers with inputs there is a small error in average.if the correct average is 48.59,the program gives average as 48.00.i tried to solve the problem and i was unable to do it.can someone help me?
im using CODEBLOCKs to write programs.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int grades[20];
int a,b,c,d,tot=0,high=0;
float avg=0;
for(a=0;a<20;a++)
{
printf("Input the Mark : ");
scanf("%d",&d);
if(d>=0&&d<=100)
grades[a]=d;
else
{
printf("OUT OF RANGE.PLEASE INPUT A VALID NUMBER.\n");
a--;
}
}
for(b=0;b<20;b++)
{
tot=tot+grades[b];
}
avg=tot/20;
high=grades[0];
for(c=0;c<20;c++)
{
if(high<grades[c])
high=grades[c];
}
printf("The Total Value is : %d\nThe Average is : %.02f\nHighest Value is : %d",tot,avg,high);
}