3039 - 【设计型】第12章:结构体与共同体 例1 定义和初始化结构体
时间限制 : 1 秒
内存限制 : 128 MB
定义一个学生结构体,数据成员包括学号,姓名,性别,生日(年月日),然后输出1个同学的数据。
题目输入
题目输出
输出一个同学的数据。
输入/输出样例
输入格式
no input needed
输出格式
1001011 王丽 F 1995/10/12
C语言解答
#include<stdio.h> struct student { long num; char name[20]; char sex; int year; int month; int day; }; int main() { int i; struct student stu[3]={{1001011,"王丽",'F',1995,10,12}, {1001012,"李军",'M',1995,5,24}, {1001013,"赵斌",'M',1994,2,25}, }; for(i=0;i<3;i++) { printf("%ld %s %c %d/%d/%d\n",stu[i].num,stu[i].name,stu[i].sex, stu[i].year,stu[i].month,stu[i].day); } return 0; }