”C語言”一問

2009-05-04 2:39 am
寫一個程式計算 : 1+ 1/2 + 1/3 + 1/4 + …..+1/n 總和,其中n 值為由鍵盤輸入
1+1/2+1/3+...+1/n這個數學公式是什麼 還有這堤C語言要如何寫 謝謝

回答 (4)

2009-05-06 1:02 am
✔ 最佳答案
#include<stdio.h>
#include<stdlib.h>
main()
{
int i,n;
float sum=0;
printf("please enter a positive integer number : ");
scanf("%d",&n);
if(n!=0)
{
printf("1");
for(i=2;i<=n;i++)
{
sum+=(float)(1.00/i);
printf("+(1/%d)",i);
}
printf("=%f\n",sum+1);
system("PAUSE");
return 0;
}
else
printf("math error\n");
system("PAUSE");
}
參考: NET
2009-05-04 6:16 am
This is the slowest diverging series that I know of. You can use a loop to do this within a few lines.

2009-05-04 06:58:12 補充:
This is one of the slowest diverging series that I know of (natural log of N). You can use a loop to do this within a few lines.
2009-05-04 4:55 am
Champion大真愛說笑...

這題很多人問過了吧...
稍微找一下就有了...
2009-05-04 3:56 am
我也好想知道這題要怎麼寫....


收錄日期: 2021-04-30 13:01:46
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090503000010KK08073

檢視 Wayback Machine 備份