C++ Programming Blog

 
 
 
/* write programs to evaluate the following to 0.0001%
 accuracy.
 (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();
}

 
 
Didn't find what you were looking for? Find more on Program to evaluate series