#include
double func(int n)
{
double s=1,k=1; //s储存结果,k储存第i各多项式的值。
int i;
for (i=2;i<=n;i++)
{
k+=i;
s+=1/k;
}
return s;
}
void main(void)
{
int s=func(11);
printf("S=%f\n",s);
getchar();
}
#include
#include
using namespace std;
double sRecursion(int n){ //递归实现
if(n == 1)
return 1.0;
else
return(sRecursion(n-1)+2.0/((1+n)*n));
}
double sIteration(int n){ //迭代实现
double sum = 0;
for(int i = 1;i <= n;i++){
sum += 2.0/((1+i)*i);
}
return sum;
}
int main(int argc, char *argv[])
{
cout<<"Please enter an integer:"<
cin>>n;
cout<<"sRecursion(n)="<
int i = 1;
sLoop: //goto实现
sum += 2.0/((1+i)*i);
if(i++ < n)
goto sLoop;
cout<<"sum after sLoop is "<
system("PAUSE");
return EXIT_SUCCESS;
}
//解体的关键应该是等差数列求和公式
#include
int main()
{
double s1=0,s2=0,i;
int j;
scanf("%d",&j);
for(i=1;i<=j;i++)
{
s1+=i;
s2+=1/s1;
}
printf("%f",s2);
}
#include
int main()
{
double s,t;
int n,i;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
t=1/i;
s=s+t;
}
printf("%lf",s);
return 0;
}
很容易的,看下就懂了~