1. 编程学习网 > 编程教程 > C语言教程 > C语言实例-使用结构体(struct)

C语言实例-使用结构体(struct)

C 语言实例

使用结构体(struct)存储学生信息。

实例

#include <stdio.h>struct student{ char name[50]; int roll; float marks; } s; int main(){ printf("输入信息:\n"); printf("名字: "); scanf("%s", s.name); printf("编号: "); scanf("%d", &s.roll); printf("成绩: "); scanf("%f", &s.marks); printf("显示信息:\n"); printf("名字: "); puts(s.name); printf("编号: %d\n",s.roll); printf("成绩: %.1f\n", s.marks); return 0; }

输出结果为:

输入信息:
名字: itjx
编号: 888
成绩: 97
显示信息:
名字: itjx
编号: 888
成绩: 97.0

本文由IT教学网整理发布,转载请注明出处:http://www.clang.cc//jiaocheng/cyuyan/1166.html

联系我们

在线咨询:点击这里给我发消息

咨询电话:400-998-2681

工作时间:7*24小时无休