Created
July 19, 2010 11:17
-
-
Save Mistat/481289 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> | |
| /** | |
| * 自然対数の底eは無理数で、その値は下記の無限級数で表される。 | |
| * 小数点3桁までの精度でeの近似値を計算するプログラムを作成 | |
| * e=1+1/1!+1/2!+1/3!・・・・・・+1/n!・・・・・ | |
| */ | |
| void main() | |
| { | |
| double sum,sum0; | |
| int i,k,kai; | |
| sum0=0; | |
| sum=1; | |
| k=0; | |
| while(sum-sum0>0.001) | |
| { | |
| k++; | |
| kai=1; | |
| for(i=1;i<k;i++) kai=kai*i; | |
| sum0=sum; | |
| sum+=1.0/kai; | |
| } | |
| printf("e=%f\n",sum); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment