65,210
社区成员
发帖
与我相关
我的任务
分享
float m=2.0f,n=1.0f; //m和n用float型
float sum=0.0f;
int a;
float temp;//使用中间变量装m,n = m在上一条中m已经被修改,这样比值一直是1
for(a=1;a <51;a++)
{
sum=sum+m/n;
temp = m;
m=m+n;
n=temp;
}
cout <<"前50项的和是" << sum <<endl;
#include <iostream.h>
void main()
{
int m=2,n=1;
float sum=0.0;
int a;
for(a=1;a <51;a++)
{
int temp;
sum=sum+(float)m/n;
temp = m;
m=m+n;
n = temp;
}
cout <<"前50项的和是" <<sum <<endl;
}
double n = 1.0;//第3行
n += 1.0;//第6行
do {
p=p+(1.0/(2*n-1))-(1.0/(2*n+1));
n++;
n++; //n应该加2
} while (1.0/(2*n-1)>=0.000001);