我有這個問題,我應該這樣做。在C中使用pow()
[報告說,創建一個程序,是能夠計算和顯示的總和小號]
像S = 1 + 1/4 + 1/8 + 1月16日......直至1/[2 POW N]
所以我的工作就可以了,用這個代碼
#include <stdio.h>
void main()
{
int n,i;
float p,s;
printf("Enter the maximum power n :");
scanf("%d",&n);
s=0;
p=0;
for (i=0;i<n;i++)
{
p+=1/pow(2, i);
s+=p;
printf("s = %f\n",s);
}
printf("The sum of this equation is :%f",&s);
}
想出但是,當我執行它總是像S = 0。 我在做什麼錯?
您的意思是1 + 1/4 + 1/8 ...或1+ ** 1/2 ** + 1/4 + 1/8 ...? –
否1 + 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + 1/64 ... – OsomePersan