#include <stdio.h>
struct scores{
char name[100];
int math;
int physics;
int eng;
};
void printscore(struct scores st)
{
printf("%s さんの点数\n",st.name);
printf(" 数学: %d 点\n",st.math);
printf(" 物理: %d 点\n",st.physics);
printf(" 英語: %d 点\n",st.eng);
}
int main(void)
{
struct scores st =
{
{"Itoh",85,79,90},
{"Satoh",60,60,75},
{"Katoh",90,55,70},
{"Mutoh",40,50,80},
};
printscore(st);
return 0;
}
{再び}C言語 構造体 関数
{再び}C言語 構造体 関数
4人の成績の結果を表示するにはどうすればようのでしょうか
Re: {再び}C言語 構造体 関数
こんな感じ?
#include <stdio.h>
typedef struct scores {
char name[100];
int math;
int physics;
int eng;
} SCORE;
void printscore(SCORE *st, int sz)
{
int i;
for (i = 0; i < sz; i++) {
printf("%s さんの点数\n", st[i].name);
printf(" 数学: %d 点\n", st[i].math);
printf(" 物理: %d 点\n", st[i].physics);
printf(" 英語: %d 点\n", st[i].eng);
}
}
int main(void)
{
SCORE st[] = {
{ "Itoh", 85, 79, 90 },
{ "Satoh", 60, 60, 75 },
{ "Katoh", 90, 55, 70 },
{ "Mutoh", 40, 50, 80 },
};
printscore(st, sizeof(st) / sizeof(st[0]));
return 0;
}
バグのないプログラムはない。
プログラムは思ったとおりには動かない。書いたとおりに動く。
プログラムは思ったとおりには動かない。書いたとおりに動く。