Created
December 1, 2012 12:33
-
-
Save alphaKAI/4182033 to your computer and use it in GitHub Desktop.
解説()入れてみた
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void main(void) | |
{ | |
int i; | |
/* 10の配列はa[0]~a[9]までだからね */ | |
int a[10]; | |
int sum = 0; | |
float average; | |
printf("入力してください\n"); | |
for(i=0; i<=9; i++){ | |
printf("%dつ目の数字を入力してください\n", i+1); | |
/* scanf("%d", &a[10], i);ではなく*/ | |
scanf("%d", &a[i]); | |
} | |
/* sum= sum+a[i]; ではなく この場合は加算代入演算子の += を使う */ | |
for(i=0; i<=9; i++){ | |
sum += a[i]; | |
} | |
average = (float)sum/10; | |
for(i=0; i<=9; i++){ | |
/* printf("%d\n", a[10]);ではなく int a[10];の場合使えるのはa[0]~a[9] つまりa[10]はない */ | |
printf("%d\n", a[i]); | |
} | |
printf("合計:%d\n", sum); | |
/* printf("平均:%d\n", average); ではなく 少数のため%f */ | |
printf("平均:%f\n", average); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment