View My Stats

Total Pageviews

Saturday 16 March 2013

sum to n terms


//prg to sum 1+1/3+1/5+1/7......nterms
#include<iostream.h>
#include<conio.h>
void main()
{
int n,j;
float sum=0,i;
cout<<"enter the value of n"<<endl;
cin>>n;
for(i=0;i<=(n-1);i++)
{sum=sum+1/(2*i+1);
 }
 cout<<sum;
 }

No comments:

Post a Comment