Skip to content

Instantly share code, notes, and snippets.

@alphaKAI
Created December 1, 2012 12:33
Show Gist options
  • Save alphaKAI/4182033 to your computer and use it in GitHub Desktop.
Save alphaKAI/4182033 to your computer and use it in GitHub Desktop.
解説()入れてみた
#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