Last active
April 27, 2019 06:15
-
-
Save proelbtn/3a79e8697fb7a86509143ffc402017bd to your computer and use it in GitHub Desktop.
e^xの近似
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
#include <stdio.h> | |
#include <stdint.h> | |
int main() { | |
double ans, index; | |
printf("index = "); | |
scanf("%lf", &index); | |
ans = 1; | |
for (int i = 20; i >= 1; i--) ans = 1 + index * ans / i; | |
printf("e^{%lf} = %.20lf\n", index, ans); | |
} |
i == 100でやった時
$ ./a.out
index = -5
e^{-5.000000} = 0.00673794699908381034
だいたい100次で精度打ち切りな感じがある。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i == 20でやった時