1 #include <stdio.h>
2 #include <string.h> // strcpy を使うため
3
4 typedef struct{ // 構造体型 student の定義
5 char name[80];
6 int mathematics;
7 int english;
8 int info_eng;
9 } student;
10
11 int cal_av(student gakusei); //プロトタイプ宣言
12
13 //=========================================================
14 // メイン関数
15 //=========================================================
16 int main(void)
17 {
18 student shimada;
19 int hei;
20
21 strcpy(shimada.name,"shimada masaharu");
22 shimada.mathematics = 92;
23 shimada.english = 88;
24 shimada.info_eng = 45;
25
26 hei=cal_av(shimada);
27
28 printf("%s no heikin = %d\n", shimada.name, hei);
29
30 return 0;
31 }
32
33 //=========================================================
34 // 平均点を計算するユーザー定義関数
35 //=========================================================
36 int cal_av(student gakusei)
37 {
38 int av;
39
40 av=(gakusei.mathematics + gakusei.english + gakusei.info_eng)/3;
41
42 return av;
43 }
shimada masaharu no heikin = 75
1 #include <stdio.h>
2 #include <string.h> // strcpy を使うため
3
4 typedef struct{ // 構造体型 student の定義
5 int math;
6 int eng;
7 } student;
8
9 student cal_av(student a[]); //プロトタイプ宣言
10
11 //=========================================================
12 // メイン関数
13 //=========================================================
14 int main(void)
15 {
16 student E2[3], heikin;
17
18 E2[0].math = 92;
19 E2[0].eng = 88;
20 E2[1].math = 42;
21 E2[1].eng = 38;
22 E2[2].math = 82;
23 E2[2].eng = 23;
24
25
26 heikin=cal_av(E2);
27
28 printf("mathematics no heikin = %d\n",heikin.math);
29 printf("English no heikin = %d\n",heikin.eng);
30
31 return 0;
32 }
33
34 //=========================================================
35 // 平均点を計算するユーザー定義関数
36 //=========================================================
37 student cal_av(student a[])
38 {
39 student hei;
40
41 hei.math = (a[0].math+a[1].math+a[2].math)/3;
42 hei.eng = (a[0].eng+a[1].eng+a[2].eng)/3;
43
44 return hei;
45 }
mathematics no heikin = 72 English no heikin = 49