Find us On Facebook

Thursday, April 7, 2011

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();
}

0 comments:

Post a Comment

Programms

C,C++,VB, PL/SQL EBOOK SEARCH ENGINE