#include <stdio.h>
#include <stdlib.h>
int main(){
typedef struct Seiseki{
int eigo;
int kokugo;
int sugaku;
float average;/*平均値*/
} SEISEKI;
int datanum,i;
SEISEKI *h_start; /* datanum 個の SEISEKI 構造体の先頭を指すポインタ*/
SEISEKI *hp;
h_start
= (SEISEKI
*)malloc(sizeof(SEISEKI
)*datanum
);
/* 英語と国語と数学の点数を DATANUM 個読み込み、3科目の平均値を計算する */
/* (ポインタとしてアクセス) */
for (i=0,hp=h_start;i<datanum;i++,hp++){
scanf("%d",&(hp
->kokugo
)); scanf("%d",&(hp
->sugaku
)); hp->average = ((hp->eigo) +(hp->kokugo) + (hp->sugaku))/3;
}
/* 3科目の平均値を表示する */
/* (配列としてアクセス) */
for (i=0;i<datanum;i++){
printf("%d 番目の人の 3 科目の平均値は%3.1f です。\n",i
+1,h_start
[i
].
average); }
/*英語と国語と数学の平均値をそれぞれ表示する*/
float eigosum=0;
float kokugosum=0;
float sugakusum=0;
for (i=0;i<datanum;i++){
eigosum+=h_start[i].eigo;
kokugosum+=h_start[i].kokugo;
sugakusum+=h_start[i].sugaku;
}
printf("英語の平均点は %3.1f 点です。\n", eigosum
/ datanum
); printf("国語の平均点は %3.1f 点です。\n", kokugosum
/ datanum
);
printf("数学の平均点は %3.1f 点です。\n", sugakusum
/ datanum
); }
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBtYWluKCl7CgkKCXR5cGVkZWYgc3RydWN0IFNlaXNla2l7CgkJaW50IGVpZ287CgkJaW50IGtva3VnbzsKCQlpbnQgc3VnYWt1OwoJCWZsb2F0IGF2ZXJhZ2U7LyrlubPlnYflgKQqLwoJfSBTRUlTRUtJOwoJCglpbnQgZGF0YW51bSxpOwoJU0VJU0VLSSAqaF9zdGFydDsgLyogZGF0YW51bSDlgIvjga4gU0VJU0VLSSDmp4vpgKDkvZPjga7lhYjpoK3jgpLmjIfjgZnjg53jgqTjg7Pjgr8qLwoJU0VJU0VLS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