#include<stdio.h>
#include<stdlib.h>
typedef struct student{
char name[15];
int score;
struct student* next;
}ST;
int main(){
ST *a,*b,*c;
a=(ST*)malloc(sizeof(ST));
printf("請輸入第一位學生姓名: ");scanf("%s",a->name);
printf("分數: ");scanf("%d",&a->score);
a->next=NULL;
b=(ST*)malloc(sizeof(ST));
printf("請輸入第二位學生姓名: ");scanf("%s",b->name);
printf("分數: ");scanf("%d",&b->score);
b->next=NULL;
a->next=b;
c=(ST*)malloc(sizeof(ST));
printf("請輸入第三位學生姓名: ");scanf("%s",c->name);
printf("分數: ");scanf("%d",&c->score);
c->next=NULL;
b->next=c;
printf("\n輸出...\n");
ST *p=a;
while(p!=NULL){
printf("學生: %s\n",p->name);
printf("分數: %d\n\n",p->score);
p=p->next;
}
system("pause");
return 0;
}
沒有留言:
張貼留言