Write a program in C to take a list of total scores from use
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
#include \"stdio.h\"
int main(void) {
int i,n;
printf(\"\ Enter the no:of students: \");
scanf(\"%d\",&n); //read the no:of students
float score[n]; //initialize score array
printf(\"\ Enter %d students total scores: \",n);
for(i=0; i<n; i++){ //read the n no:of students total scores
scanf(\"%f\",&score[i]);
}
printf(\"\ The grades of students are:\");
char grade;
for(i=0; i<n; i++){ //find the grade of n no:of students, and print it
if(score[i] >= 90 && score[i] < 100) //if the score is greater than 90 and less than 100
grade = \'A\';
else if(score[i] > 80) //else if the greater than 80
grade = \'B\';
else if(score[i] > 70) //else if the greater than 70
grade = \'C\';
else if(score[i] > 60) //else if the greater than 60
grade = \'D\';
else if(score[i] < 40) //else if the less than 40
grade = \'F\';
printf(\"\ Student %d : %c\",(i+1),grade);
}
return 0;
}
-----------------------------------------------------------------------------------
Firstly you have to read the no:of students the user needs to find grades, then according to the no:of students, read all that \'n\' no:of students total scores into a float array. After that iterate over each score in the array and determine the grade with the help of if-else statements, and finally print each students grades.
-----------------------------------------------------------------------------------
OUTPUT:
