用c语言编程,某组有五个学生,每个人有一条学生信息,学生信息包括学号、姓名、性别和入学分数。设计一个程序,输入学生信息,再通过指针方式输出这些信息。
时间: 2024-02-22 17:59:33 浏览: 75
好的,我可以为您提供这样一个C语言程序,它可以实现您所需的功能,您可以参考以下代码:
```c
#include <stdio.h>
struct student {
int id; // 学号
char name[20]; // 姓名
char gender; // 性别
float score; // 入学分数
};
int main() {
struct student s[5];
struct student *p;
int i;
// 输入学生信息
printf("请输入五个学生的信息:\n");
for (i = 0; i < 5; i++) {
printf("请输入第%d个学生的学号:", i+1);
scanf("%d", &s[i].id);
printf("请输入第%d个学生的姓名:", i+1);
scanf("%s", s[i].name);
printf("请输入第%d个学生的性别:", i+1);
scanf(" %c", &s[i].gender);
printf("请输入第%d个学生的入学分数:", i+1);
scanf("%f", &s[i].score);
}
// 通过指针方式输出学生信息
printf("\n通过指针方式输出五个学生的信息:\n");
p = s;
for (i = 0; i < 5; i++) {
printf("学号:%d\t姓名:%s\t性别:%c\t入学分数:%.2f\n", p->id, p->name, p->gender, p->score);
p++;
}
return 0;
}
```
这个程序使用了结构体来存储学生信息,通过循环输入学生信息,再通过指针方式遍历结构体数组并输出信息。如果您有疑问或需要进一步帮助,请随时告诉我。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)