结构体数组的输入与输出
输入学生的姓名、性别、年龄
使用结构体输出对应数据
#include<stdio.h> #include<string.h> #include<stdlib.h> struct student { char name[10]; char sex; long age; float score[3]; }; int main(){ struct student stu; int i; scanf("%s %c %ld",stu.name,&stu.sex,&stu.age); for(i=0;i<3;i++) { scanf("%f",&stu.score[i]); } printf("Name Sex Age Score1 Score2 Score3\n"); printf("%-8s %-2c %8ld",stu.name,stu.sex,stu.age); for(i=0;i<3;i++) { printf("%8.2f",stu.score[i]); } return 0; }