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

C语言教程评论

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

使用结构体(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;
}

输出结果为:文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-shiyongjiegoutistruct.html

输入信息:
名字: nowcoder
编号: 123
成绩: 89
显示信息:
名字: nowcoder
编号: 123
成绩: 89.0
文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-shiyongjiegoutistruct.html文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-shiyongjiegoutistruct.html
运营不易,
感谢支持!
weinxin
我的微信
我的微信公众号
我的微信公众号扫一扫
weinxin
我的公众号
 
公式库网
  • 本文由 公式库网 发表于 2021年12月7日20:53:43
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202112/c-yuyanshili-shiyongjiegoutistruct.html

发表评论