-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31c755b
commit 38ec059
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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; | ||
} |