配列の各要素に先頭から順に 1,2,3,4,5 を代入して表示

明解C言語 入門編 > 5. 配列 >

配列の各要素に先頭から順に 1,2,3,4,5 を代入して表示

C


#include <stdio.h>
int main(int argc, char* argv[])
{
int score[5];

score[0] = 1;
score[1] = 2;
score[2] = 3;
score[3] = 4;
score[4] = 5;

printf("点数1 = %d\n", score[0]);
printf("点数2 = %d\n", score[1]);
printf("点数3 = %d\n", score[2]);
printf("点数4 = %d\n", score[3]);
printf("点数5 = %d\n", score[4]);

return 0;
}

実行結果

T:\>lesson030\project1.exe
点数1 = 1
点数2 = 2
点数3 = 3
点数4 = 4
点数5 = 5