In: Computer Science
C LANGUAGE
Ask user how many scores there are, then ask for each score. Then calculate the average score and scores below 60. Then display the average score and number of scores below 60
Explanation:
Here is the code which asks for the number of scores from the user and then it takes those number of scores from the user and then calculates the sum of the entered scores and also the number of scores below 60.
Then the average and the number of scores below 60 are printed.
Code:
#include <stdio.h>
int main()
{
int scores;
printf("Enter number of scores: ");
scanf("%d", &scores);
int scores_below_60 = 0;
int sum = 0;
for (int i = 0; i < scores; i++) {
int value;
scanf("%d", &value);
sum = sum + value;
if(value<60)
scores_below_60++;
}
float avg = (float)sum/(float)scores;
printf("Average is: %f\n", avg);
printf("Number of scores below 60: %d\n", scores_below_60);
return 0;
}
output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!