?? 改進的學生結構指針數組.cpp
字號:
#include<stdio.h>
#include<stdlib.h>
#define NULL 0
struct stu{
int num,ch,ma,en;
struct stu *next;
};
struct stu *creat();
void main( )
{
struct stu *head,*p;
float avc=0, avm=0, ave=0;
int i=0;
head= creat();
if(head == NULL)
printf("沒有生成鏈表。\n");
else{
for (p=head; p; p= p->next){
avc+=p->ch ;
avm+=p->ma ;
ave+=p->en ;
i++;
}
printf("語文、數學、英語的平均成績:\n");
printf("%6.2f %6.2f %6.2f\n",avc/i,avm/i,ave/i);
}
}
struct stu *creat(){
struct stu *head, *tail, *p;
int ch,ma,en,num,i=1;
head = tail = NULL;
printf("說明:結束時請輸入0 0 0 0。\n");
printf("輸入第%d個學生的學號以及語文、數學、英語成績:\n",i);
scanf("%d%d%d%d",&num,&ch,&ma,&en);
while (num){
p = (struct stu *)malloc(sizeof(struct stu));
p->num = num;
p->ch = ch;
p->ma = ma;
p->en = en;
p->next = NULL;
if(head == NULL) head = p;
else tail->next = p;
tail = p;
i++;
printf("輸入第%d個學生的學號以及語文、數學、英語成績:\n",i);
scanf("%d%d%d%d",&num,&ch,&ma,&en);
}
return head;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -