This program is wrotten by me college's teacher, and i so confuse and do not understand why is like this coding.
#include<stdio.h>
void main()
{
int i,j,class_size,mark;
int freq[11]={0}; //why make freq[11] for 11 variables?//
printf("This program produces a bar chart\n");
printf("showing marks distribution...\n");
printf("\nHow many students?");
scanf("%d", &class_size);
//make frequecy table
printf("Key in %d marks (Valid mark 0 to 99)\n\n", class_size);
for( i = 1; i<= class_size; i++)
{
printf("Mark #%d:", i);
scanf("%d", &mark);
if (mark>=0 && mark <=99)
freq[mark/10]+=1; //why need to devide by 10?//
else
freq[10]+=1;}
//print bar chart
printf("\n\nMarks Distribution\n\n");
printf("Mark Range #students Bar Chart\n");
printf("---------------------\n");
for(i=0;i<=9;i++)
{
printf("%d-%d\t\t %d\t",i*10,i*10+9,freq[i]);
for(j=1;j<=freq[i];j++)//do not understand this part also//
printf("*");
printf("\n");
}
if (freq[i]>0) //why freq[i]//
printf("Invalid marks \t %d \n", freq[i]);
printf("\n\n***End of Output***\n\n");
}
Okay here is the end of the program coding. Thx for viewing. :D