(B) SUM = 1+[(1/2)raise to 2]+[(1/3)raise to 3]+.....
#include<math.h>
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int num;
cout<<"Enter the number:- ";
cin>>num;
float r,sum=0,p;
int k,i;
for(k=1,i=1;i<=num;i++,k++)
{
r=1.0/k;
p=pow(r,i);
sum=sum+p;
}
cout<<"\n\nSUM = "<<sum;
getch();
}
#include<math.h>
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int num;
cout<<"Enter the number:- ";
cin>>num;
float r,sum=0,p;
int k,i;
for(k=1,i=1;i<=num;i++,k++)
{
r=1.0/k;
p=pow(r,i);
sum=sum+p;
}
cout<<"\n\nSUM = "<<sum;
getch();
}
0 comments:
Post a Comment