C 练习实例71

3363 1
LZH实名认证 2022-3-18 22:23:35 | 显示全部楼层 |阅读模式
题目:编写input()和output()函数输入,输出5个学生的数据记录。

程序分析:无。

程序源代码:

//  Created by www.runoob.com on 15/11/9.
//  Copyright © 2015年 菜鸟教程. All rights reserved.
//

#include<stdio.h>
#include<stdlib.h>
typedef struct{
    char name[20];
    char sex[5];
    int  age;
}Stu;
void input(Stu*stu);
void output(Stu*stu);
int main()
{
    Stu stu[5];
    printf("请输入5个学生的信息:姓名 性别 年龄:\n");
    input(stu);
    printf("5个学生的信息如下:\n姓名  性别  年龄\n");
    output(stu);
   
    system("pause");
    return 0;
}
void input(Stu*stu)
{
    int i;
    for(i=0;i<5;i++)
        scanf("%s%s%d",stu.name,stu.sex,&(stu.age));
}
void output(Stu*stu)
{
    int i;
    for(i=0;i<5;i++)
        printf("%s %s %d\n",stu.name,stu.sex,stu.age);
}
以上程序执行输出结果为:

请输入5个学生的信息:姓名 性别 年龄:
aaa m 15
bbb m 16
ccc m 15
ddd m 17
eee m 16
5个学生的信息如下:
姓名  性别  年龄
aaa m 15
bbb m 16
ccc m 15
ddd m 17
eee m 16
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行