C 练习实例71

C 语言教程 · 2019-02-22 11:41:30

题目:编写input()和output()函数输入,输出5个学生的数据记录。

程序分析:无。

程序源代码:

//  Created by www.codercto.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[i].name,stu[i].sex,&(stu[i].age));
}
void output(Stu*stu)
{
    int i;
    for(i=0;i<5;i++)
        printf("%s %s %d\n",stu[i].name,stu[i].sex,stu[i].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

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

Learning PHP 5

Learning PHP 5

David Sklar / O'Reilly / July, 2004 / $29.95

Learning PHP 5 is the ideal tutorial for graphic designers, bloggers, and other web crafters who want a thorough but non-intimidating way to understand the code that makes web sites dynamic. The book ......一起来看看 《Learning PHP 5》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具