#include <stdio.h> #include <stdlib.h> int f(int n){ //計算n!的遞迴函式 return (n>1)?n*f(n-1):1; } int main(){ double e=1.0; int i; for(i=1;i<10;i++) //做到第十項 e+=(1.0/((double)f(i))); printf("e approximate to 10th elements is %lf\n",e); system("pause"); return 0; }
參考資料
每天和程式作伍的研究生
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. Five Filters recommends: