发布网友 发布时间:2024-10-23 21:35
共5个回答
热心网友 时间:2024-10-27 01:30
#include <stdio.h>
int main()
{
double s=0;
int n,t=0;
printf("请输入n\n");
scanf("%d",&n);
int i;
for(i=1;i<=n;i++)
{
t+=i;
s+=1.0/t;
}
printf("结果为:%f",s);
return 0;
}
热心网友 时间:2024-10-27 01:27
你的求职 是有规律的 n项相加的和
其实到最后就是sum=2(1-1(1/(1+n)))
#include "stdio.h"
main()
{
int n;
float value=0;
printf("please input a num:");
scanf("%d",&n);
if(n>=1)
{
value=2*(1.0000-(1.0000/(n+1)));
}
printf("value=%f\n",value);
}
热心网友 时间:2024-10-27 01:23
double S(int n)
{
if(n == 1)
return 1.0;
return S(n-1) + 2.0 / n / (n+1.0);
}
热心网友 时间:2024-10-27 01:27
#include <iostream.h>
void main()
{
int n = 0, m = 0;
double sum = 0.0;
cin>>n;
for (int i = 1; i <= n; i ++)
{
m = 0;
for (int j = 1; j <= i; j ++)
{
m += j;
}
sum += 1.0/m;
}
cout<<sum<<"\n";
}
热心网友 时间:2024-10-27 01:29
#include<conio.h>
#include<stdio.h>
#include<string.h>
float fun(int n)
{
int i,s1=0;
float s=0.0;
for (i=1;i<=n;i++)
{s1=s1+i;
s=s+1.0/s1;
}
return s;}
main()
{int n;
float s;
printf("\n Pleasa enter N:");
scanf("%d",&n);
s=fun(n);
printf("The result is :%f\n",s);}