zhihongchan 2021-05-19 19:50 采纳率: 76.9%

# C语言题目。电脑小白完全懵逼[face]emoji:011.png[/face]

C语言题目。电脑小白完全懵逼[face]emoji:011.png[/face]
• 写回答

#### 1条回答默认 最新

• benbenli 2021-05-20 02:33
关注
``````
#include <stdio.h>

int main()
{
int n = 0;
float sum = 0;
while (1)
{
float g;
printf("Enter a grade (0-100) [-1 to end]:\n");
scanf("%f", &g);
if (g == -1)
break;
else if (g > 100 || g < 0)
{
printf("Marks out of range.\n");
continue;
}
else if (g >= 80)
printf("Excellent\n");
else if (n >= 65)
printf("Very Good\n");
else if (g >= 50)
printf("Average\n");
else if (g >= 40)
printf("Poor\n");
else
printf("Fail\n");

++n;
sum += g;
}

printf("The total mark is %.2f, and the average is %.2f\n", sum, sum / n);

return 0;
}

// output:
Enter a grade (0-100) [-1 to end]:
10
Fail
Enter a grade (0-100) [-1 to end]:
60
Average
Enter a grade (0-100) [-1 to end]:
89
Excellent
Enter a grade (0-100) [-1 to end]:
-2
Marks out of range.
Enter a grade (0-100) [-1 to end]:
200
Marks out of range.
Enter a grade (0-100) [-1 to end]:
38
Fail
Enter a grade (0-100) [-1 to end]:
-1
The total mark is 197.00, and the average is 49.25``````
本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论

#### 悬赏问题

• ¥15 需要完整的python代码并解释