用c语言编写统计多个学生信息的编程
时间: 2024-03-10 18:51:05 浏览: 17
好的,以下是一个用 C 语言编写的简单示例代码,用于统计多个学生的信息:
```c
#include <stdio.h>
struct student {
char name[50];
int age;
float height;
float weight;
};
int main() {
int count;
printf("请输入学生数量:");
scanf("%d", &count);
struct student students[count];
for (int i = 0; i < count; i++) {
printf("\n请输入第 %d 个学生的信息:\n", i + 1);
printf("姓名:");
scanf("%s", students[i].name);
printf("年龄:");
scanf("%d", &students[i].age);
printf("身高(米):");
scanf("%f", &students[i].height);
printf("体重(千克):");
scanf("%f", &students[i].weight);
}
printf("\n所有学生的信息如下:\n");
for (int i = 0; i < count; i++) {
printf("\n第 %d 个学生的信息:\n", i + 1);
printf("姓名:%s\n", students[i].name);
printf("年龄:%d\n", students[i].age);
printf("身高:%.2f 米\n", students[i].height);
printf("体重:%.2f 千克\n", students[i].weight);
}
return 0;
}
```
该代码首先要求用户输入学生数量,然后创建一个名为 `students` 的包含 `count` 个元素的结构体数组。在循环中,用户可以依次输入每个学生的信息,并将其存储在相应的结构体中。最后,程序将输出所有学生的信息。
需要注意的是,这只是一个简单的示例代码,实际的学生信息统计程序可能需要更多的功能和复杂的逻辑。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)