Skip to content

Commit

Permalink
Create sum.c
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinzEugen7 committed Nov 26, 2015
1 parent 31c755b commit 38ec059
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions C/Basic/sum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>

double sum(double data[], int n)
{
int i;
double total = 0.0; // 変数の宣言

for(i=0; i<n; i++){
total += data[i]; // 合計を計算
}

return total; // 合計を返す
}


int main(void)
{
double data[] = {1.0,2.0,3.0,4.0,5.0}; // 配列の宣言
int n = sizeof(data) / sizeof(data[0]); // 配列の要素数(データ数)

printf("合計は%f", sum(data,n)); // 計算結果を出力

return 0;
}

0 comments on commit 38ec059

Please sign in to comment.