What will be the c code for 1+1/3+1/5+....1/2n+1?

2015-11-04 5:16 pm
更新1:

What will be the C program for the above given result. I wanna compile it in Turbo C++.

回答 (1)

2015-11-04 5:35 pm
/*
* C program to determine and print the sum of the following harmonic series for
* a given value of n: 1+1/3+1/5+………………+1/(2n+1)
*/
#include<stdio.h>

void main()
{
int n;
float i, sum, t;
printf("1 + 1/3 + 1/5 + ... + 1/(2n+1)\n");

n=25;

sum=0;
for(i=0; i<=n; i++)
{
t=1/(2*i+1);
sum=sum+t;
}
printf("%f",sum);
}


收錄日期: 2021-04-21 14:55:14
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20151104091644AA60GYp

檢視 Wayback Machine 備份