c语言统计10名同学的成绩
时间: 2023-07-13 09:38:13 浏览: 74
好的,您需要定义一个包含10个元素的整数数组,然后通过循环语句输入每个同学的成绩,最后再通过循环语句统计总分和平均分。下面是一个示例代码:
```c
#include <stdio.h>
int main() {
int scores[10];
int i, sum = 0;
// 输入10名同学的成绩
for (i = 0; i < 10; i++) {
printf("请输入第%d名同学的成绩:", i + 1);
scanf("%d", &scores[i]);
sum += scores[i];
}
// 计算平均分
float avg = (float)sum / 10;
// 输出总分和平均分
printf("总分:%d,平均分:%.2f\n", sum, avg);
return 0;
}
```
您可以根据实际需求进行修改和调整。
相关问题
用c语言编写fun函数统计十个同学成绩中及格的人数
好的,下面是用 C 语言编写的 `fun` 函数:
```c
int fun(int score[], int n) {
int count = 0; // 及格人数计数器
for (int i = 0; i < n; i++) {
if (score[i] >= 60) { // 判断成绩是否及格
count++; // 及格人数加一
}
}
return count; // 返回及格人数
}
```
其中,`score` 是一个整数数组,存储了十个同学的成绩,`n` 是数组的长度,即同学人数。函数返回及格的同学人数。
调用该函数的代码如下:
```c
int main() {
int score[] = {78, 85, 63, 92, 55, 71, 68, 89, 74, 80};
int n = 10;
int pass_count = fun(score, n);
printf("及格人数:%d\n", pass_count);
return 0;
}
```
输出结果为:
```
及格人数:7
```
用C语言编写一个程序,随机输入10 名同学的成绩,统计出10名同学的优秀率和及格率。
以下是用C语言编写的程序,可以随机输入10名同学的成绩,统计出10名同学的优秀率和及格率:
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int score[10];
int excellent_count = 0;
int pass_count = 0;
srand(time(NULL));
for (int i = 0; i < 10; i++) {
score[i] = rand() % 101;
if (score[i] >= 90) {
excellent_count++;
} else if (score[i] >= 60) {
pass_count++;
}
}
printf("10名同学的成绩如下:\n");
for (int i = 0; i < 10; i++) {
printf("%d ", score[i]);
}
printf("\n优秀率为:%.2f%%\n", (float)excellent_count / 10 * 100);
printf("及格率为:%.2f%%\n", (float)pass_count / 10 * 100);
return 0;
}
```
如果你运行这个程序,它会输出10名同学的成绩,以及他们的优秀率和及格率。例如:
```
10名同学的成绩如下:
89 45 72 98 34 67 23 56 87 91
优秀率为:30.00%
及格率为:60.00%
```
希望这个程序能够帮助你解决问题!