题目描述如图:
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | //Powered by TCreopargh #include<stdio.h> int power(int base, int expn) { int result=1,i; for(i=0;i<expn;i++) result*=base; return result; } int main(int argc, char* argv[]) { int n,i; double sum=0; scanf("%d",&n); for(i=1;i<=n;i++) { sum+=(double)((power(-1,i-1))*power(2,i))/(double)((power(2,i)+power(-1,i))*(power(2,i+1)+power(-1,i+1))); } printf("%0.6lf\n",sum); return 0; } |
发表回复