WAP to compute the sum of the first n terms of the following series S = 1+1/2+1/3+1/4+……



#include<iostream.h>
#include<conio.h>
class summation
{
double sum;
public:
void  s();
};
void  summation::s()
{
sum=0;
int n;
cout<<"enter the number of terms whose sum you want in the series"<<endl;
cin>>n;
                for(int i=1;i<=n;i++)
       {
                sum=sum+(1/(double)i);
       }
cout<<"the sum is :"<<sum;
}
void main()
{
clrscr();
summation obj;
obj.s();
getch();
}


Output:-


Comments