【求助】不用数组如何存储多条记录,比如不同学号和各科成绩,并且显示出来.....
如何用最简单的办法编程呢,我们老师让编一个小程序,不用数组,然后输入每个人的各科成绩,但是如果不用数组的话,怎么做才能存储多条记录呢?
root@~ #cat 1.c #include <stdio.h> struct student { int id; int sa; int sb; int sc; }; int main (void) { struct student a,b,c,d,e; //定义5个学生的结构 struct student input (struct student boy); void display (struct student boy); //录入数据 a=input(a); b=input(b); c=input(c); d=input(d); e=input(e); //显示5个学生的各科成绩总分等。 display(a); display(b); display(c); display(d); display(e); return 0; } struct student input (struct student boy) { printf ("Enter id:"); scanf ("%i",&boy.id); printf ("Enter score a:"); scanf ("%i",&boy.sa); printf ("Enter score b:"); scanf ("%i",&boy.sb); printf ("Enter score c:"); scanf ("%i",&boy.sc); return boy; } void display (struct student boy) { printf (" \nboy id:%i\n",boy.id); printf ("score a:%i\n",boy.sa); printf ("score b:%i\n",boy.sb); printf ("score c:%i\n",boy.sc); printf ("Sum of score:%i\n",boy.sa+boy.sb+boy.sc); printf ("Average of score:%.2f\n",(float)(boy.sa+boy.sb+boy.sc)/3); }