Created
April 24, 2020 03:19
-
-
Save ateruimashin/4f5de48af233f54c0a36b6b9856c4870 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> | |
#define N 100 | |
int main(int argc, char const *argv[]) { | |
float s_1 = 0.0, s_2 = 0.0, t = 1.0 - 1.0 / (N + 1.0); | |
int k; | |
/*配列初期化*/ | |
float inc[100], dec[100]; //s値格納配列。配列作ったのはまとめて表示したかったから。 | |
for(k = 0; k < N; k++){ | |
inc[k] = 0.0; | |
dec[k] = 0.0; | |
} | |
/*課題部分*/ | |
for(k = 1; k <= N; k++){ | |
s_1 += 1.0 / (k * (k + 1.0)); | |
inc[k-1] = s_1; //inc内の順番はkが大きくなる順 | |
} | |
for(k = N; k >= 1; k--){ | |
s_2 += 1.0 / (k * (k + 1.0)); | |
dec[N - k] = s_2; //dec内の順番はkが小さくなる順 | |
} | |
//各kにおけるs値と最終的な誤差を表示 | |
for(k = 0; k < N; k++){ | |
printf("*s値表示\n"); | |
printf("inc[%d] = %e, dec[%d] = %e\n", k, inc[k], k, dec[k]); | |
// printf("*各kにおける誤差の表示\n"); | |
// printf("dec[%d]_error = %e, dec[%d]_error = %e\n", k, inc[k] - t, k, dec[k] - t); | |
printf("\n"); | |
} | |
printf("t = %e\n", t); | |
printf("conclusive_inc_error = %e\n", inc[N -1] - t); | |
printf("conclusive_inc_error = %e\n", dec[N -1] - t); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment