用结构体输入学生成绩
时间: 2024-02-22 07:57:28 浏览: 23
好的,我可以为您提供一个简单的示例代码,用结构体输入学生成绩:
```
#include <stdio.h>
struct student {
char name[50];
int id;
float grade;
};
int main() {
struct student s;
printf("Enter student name: ");
scanf("%s", s.name);
printf("Enter student ID: ");
scanf("%d", &s.id);
printf("Enter student grade: ");
scanf("%f", &s.grade);
printf("\nStudent name: %s\n", s.name);
printf("Student ID: %d\n", s.id);
printf("Student grade: %.2f\n", s.grade);
return 0;
}
```
在上面的代码中,我们首先定义了一个名为 `student` 的结构体,它包含了学生的姓名、学号和成绩。然后我们在 `main()` 函数中定义了一个 `s` 变量,它是一个 `student` 类型的结构体。
接着,我们使用 `scanf()` 函数分别输入学生的姓名、学号和成绩,并将它们存储到 `s` 变量的相应成员中。最后,我们使用 `printf()` 函数将学生的信息输出到屏幕上。
希望这个示例能够帮助您了解如何使用结构体输入学生成绩。
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.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)