[問題] 請教結構指標的題目
大家好,小弟目前在自學C語言,買書作習題發現有個題目不懂的地方
還請大家多多幫忙。(實在是想不透阿~~~)
題目:利用一個指向結構data型態的指標,來指向結構陣列student,
如下敘:
struct data *ptr;
ptr=student;
是以ptr指標算術運算完成下面的程式設計。
#include <stdio.h>
#include <stdlib.h>
#define MAX 6
int main(void)
{
int i,sum=0;
struct data
{
char name[10];
int math;
}student[MAX]={{"Jenny",63},{"Teresa",88},
{"Kimi Chen",57},{"Lily Kao",92},
{"David",48},{"Bird",23}};
struct data high=student[0];
for(i=0;i<MAX;i++)
{
if(high.math<student[i].math)
{
strcpy(high.name,student[i].name);
high.math=student[i].math;
}
}
printf("%s的數學成績最高是%d分\n",high.name,high.math);
printf("\n以下為不及格的名單:\n");
for(i=0;i<MAX;i++)
if(student[i].math<60)
printf("%s不及格,成績為=%d\n",student[i].name,
student[i].math);
for(i=0;i<MAX;i++)
sum+=student[i].math;
printf("\n平均成績=%.2f\n",(float)sum/MAX);
system("pause");
return 0;
}
※ 編輯: elohacp4 (114.45.159.145), 04/26/2015 22:16:26
→
04/26 22:38, , 1F
04/26 22:38, 1F
→
04/27 21:33, , 2F
04/27 21:33, 2F
→
04/27 21:36, , 3F
04/27 21:36, 3F
→
04/27 22:00, , 4F
04/27 22:00, 4F
→
04/28 08:44, , 5F
04/28 08:44, 5F
→
04/28 09:40, , 6F
04/28 09:40, 6F
→
04/28 10:25, , 7F
04/28 10:25, 7F
→
04/28 20:13, , 8F
04/28 20:13, 8F
→
04/28 20:29, , 9F
04/28 20:29, 9F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章