求1 + 2/3 + 3/5 + 4/7 + 5/9 + … 的前20项之和。用C语言
发布网友
发布时间:2024-10-23 11:56
我来回答
共5个回答
热心网友
时间:2024-11-03 04:44
#include<stdio.h>
void main(){
int i;
float sum=0;
for(i=0;i<20;i++){
sum=(i+1)/(2*i+1);
}
printf("%f\n", sum);
}
热心网友
时间:2024-11-03 04:44
void MyExit(){
system("pause");
}
int main()
{
atexit(MyExit);
int i=2;
double result=1;
while(i<21){
result+=i*1.0/(i+1);
i++;
}
cout<<result<<endl;
return 0;
}
热心网友
时间:2024-11-03 04:45
/*
* liu.c
*
* Copyright 2014 QCQ <qinchuanqing918@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int i;
double sum = 1.0;
for(i = 1; i < 20; i++)
{
sum+= (i + 1) * 1.0 / (i + 2);
printf("%lf\n",sum);
}
printf("%lf\n",sum);
return 0;
}
热心网友
时间:2024-11-03 04:45
#include<stdio.h>
void main()
{
int i = 1;
double result = 0;
for(i; i <=20; i++)
{
result+=(double)i/((i*2)-1);
}
printf("结果是%f\n",result);
}
热心网友
时间:2024-11-03 04:46
#include<stdio.h>
void main()
{
float sum=1.0;
float temp;
for(float i=2.0;i<=20.0;i++)
{
temp=i/(2*i-1);
sum+=temp;
}
printf("%f\n",sum);
}