posted by
dongthevo
on Aug 18
#include<iostream>
#include<cmath>
using namespace std;
int main()
{ //S(n) = 1 + 1/1 + 2 + 1/ 1 + 2 + 3 + ….. + 1/ 1 + 2 + 3 + …. + N
float S=0,n,x=1,a=0,dem=1;
for(;S==0;S=0,dem=1)
{
cout<<"Nhap n:";
cin>>n;
for(;dem<=n;++dem,x=1,a=0)
{
for(;x<=dem;++x)
{
a=a+x;
}
S=S+1/a;
}
cout<<"S="<<S;
cout<<endl;
}
return 0;
}
reply