Skip to content

Instantly share code, notes, and snippets.

  • Select an option

  • Save Mistat/464382 to your computer and use it in GitHub Desktop.

Select an option

Save Mistat/464382 to your computer and use it in GitHub Desktop.
/**
* 課題2
*
* 5つの配列を格納する配列Dataに任意の5つの数字を格納(初期値設定)して、
* 合計と平均を求めるプログラムを作成
*/
#include<stdio.h>
void main()
{
//配列の宣言とデータの初期値設定
int array[] = {10,20,30,40,50};
double sum=0,ave=0;
int i;
//合計の計算
//平均の計算
for (i = 0 ; i < 5 ; i++) {
sum += array[i];
}
ave = sum / 5;
//計算の結果表示
printf("sum = %.5f, ave = %.5f\n", sum, ave);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment