Added 'repetition of calc.' of question 4.

parent 07c0477e
...@@ -10,10 +10,15 @@ int fact(int x) {return x > 0 ? x * fact(x-1) : 1; } ...@@ -10,10 +10,15 @@ int fact(int x) {return x > 0 ? x * fact(x-1) : 1; }
int main(void) { int main(void) {
printf("fact 8: %d\n", fact(8)); printf("fact 8: %d\n", fact(8));
float e = 1; float first, e;
for(int i = 1; i < 20; i++ ) { for(int r = 0; r < 2; r++ ) {
e += 1.f / fact(i); e = 1;
for(int i = 1; i < 20; i++ ) {
e += 1.f / fact(i);
}
printf("approx. e: %.80f\n", e);
first = e;
} }
printf("approx. e: %.80f\n", e); printf("diff: %.80f = (first - e)\n", first - e);
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment