Q:

# Write a C program to count the number of students belonging to each of following groups of marks

Given below is the list of marks obtained by a class of 50 students in an annual examination.

43 65 51 27 79 11 56 61 82 09 25 36 07 49 55 63 74 81 49 37

40 49 16 75 87 91 33 24 58 78 65 56 76 67 45 54 36 63 12 21

73 49 51 19 39 49 68 93 85 59

Write a C program to count the number of students belonging to each of following groups of

marks:

0–9, 10–19, 20–29,.....,100.

``````    int marks[] = {43,65,51,27,79,11,56,61,82,9,25,36,7,49,55,63,74,81,49,37,40,49,16,75,87,91,33,24,58,78,65,56,76,67,45,54,36,63,12,21,73,49,51,19,39,49,68,93,85,58};
int marksRangesCount[]={0,0,0,0,0,0,0,0,0,0};
//printf("%d\n",(int)sizeof(marks));
for(int i=0;i<50;i++)
{
if(marks[i]>=0 && marks[i]<=9)
marksRangesCount[0]++; //same like : marksRangesCount[0]=marksRangesCount[0]+1;
else if(marks[i]>=10 && marks[i]<=19)
marksRangesCount[1]++; //same like : marksRangesCount[0]=marksRangesCount[0]+1;
else if(marks[i]>=20 && marks[i]<=29)
marksRangesCount[2]++; //same like : marksRangesCount[0]=marksRangesCount[0]+1;
else if(marks[i]>=30 && marks[i]<=39)
marksRangesCount[3]++; //same like : marksRangesCount[0]=marksRangesCount[0]+1;
else if(marks[i]>=40 && marks[i]<=49)
marksRangesCount[4]++; //same like : marksRangesCount[0]=marksRangesCount[0]+1;
else if(marks[i]>=50 && marks[i]<=59)
marksRangesCount[5]++; //same like : marksRangesCount[0]=marksRangesCount[0]+1;
else if(marks[i]>=60 && marks[i]<=69)
marksRangesCount[6]++; //same like : marksRangesCount[0]=marksRangesCount[0]+1;
else if(marks[i]>=70 && marks[i]<=79)
marksRangesCount[7]++; //same like : marksRangesCount[0]=marksRangesCount[0]+1;
else if(marks[i]>=80 && marks[i]<=89)
marksRangesCount[8]++; //same like : marksRangesCount[0]=marksRangesCount[0]+1;
else if(marks[i]>90 && marks[i]<=100)
marksRangesCount[9]++; //same like : marksRangesCount[0]=marksRangesCount[0]+1;

//printf("%d\n",marks[i]);
}
printf("Count of marks ranges:\n-----------------------------\n");
printf("0 to 9 : %d\n",marksRangesCount[0]);
printf("10 to 19 : %d\n",marksRangesCount[1]);
printf("20 to 29 : %d\n",marksRangesCount[2]);
printf("30 to 39 : %d\n",marksRangesCount[3]);
printf("40 to 49 : %d\n",marksRangesCount[4]);
printf("50 to 59 : %d\n",marksRangesCount[5]);
printf("60 to 69 : %d\n",marksRangesCount[6]);
printf("70 to 79 : %d\n",marksRangesCount[7]);
printf("80 to 89 : %d\n",marksRangesCount[8]);
printf("90 to 100 : %d\n",marksRangesCount[9]);``````

output:

``````Count of marks ranges:
-----------------------------
0 to 9 : 2
10 to 19 : 4
20 to 29 : 4
30 to 39 : 5
40 to 49 : 8
50 to 59 : 8
60 to 69 : 7
70 to 79 : 6
80 to 89 : 4
90 to 100 : 2``````