PTA:7-4 Store Information of Students Using Structure (10分)

    技术2026-02-24  15

    题目要求为定义一个结构体,向里面输入数据,然后输出,注意定义时输入的数据顺序为 name,roll,marks,输出时顺序为roll,name,marks

    #include<stdio.h> struct student{ //定义结构体 char name[10]; int roll; float marks; }; int main(){ struct student stu[5]; //定义结构体数组stu int i,j; for(i=0;i<5;i++){ scanf("%s %d %f",&stu[i].name,&stu[i].roll,&stu[i].marks); } struct student *p; for(p=stu;p<stu+5;p++){ printf("Roll number: %d\n",p->roll); printf("Name: %s\n",p->name); printf("Marks: %.1f\n",p->marks); } }
    Processed: 0.020, SQL: 9