Description:
Build student information with structure, student information including number, name, score, build a chain of n students
Table and outputs the linked list.
Input:
Enter student information at a time including number, name. 0 0 0 End the program.
Sample Input:
C1001 Li 70m1002 He 89E1003 Xie 83m1004 Wu 92E1005 Bao Sample output:c1001 Li 70m1002 He 89E1003 Xie 83m1004 Wu 92E1005 Bao 80
1#include <stdio.h>2#include <stdlib.h>3 structStudent4 {5 Charnum[ -];6 Charname[ -];7 floatscore;8 structStudent *Next;9 };Ten intN; One structStudent *creat () A { - structStudent *head,*p1,*P2; -n=0; theP1=p2= (structStudent *) malloc (sizeof(structstudent)); -scanf"%s%s%f",p1->num,p1->name,&p1->score); -Head=NULL; - while(p1->num!=0&&p1->name!=0&&p1->score!=0) + { -n+=1; + if(n==1) AHead=P1; at Else -p2->next=P1; -P2=P1; -P1= (structStudent *) malloc (sizeof(structstudent)); -scanf"%s%s%f",p1->num,p1->name,&p1->score); - } inp2->next=NULL; - returnhead; to } + voidPrintstructStudent *head) - { the structStudent *p; *p=head; $ if(head!=NULL)Panax Notoginseng { - Do the { +printf"%s%s%g\n",p->num,p->name,p->score); AP=p->Next; the} while(p!=NULL); + } - } $ intMain () $ { - structStudent *head; -Head=creat (); the print (head); - return 0;Wuyi}
C Language: Swust OJ, program Design C experiment six structural body topic three student structure list (0068)