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

sum to series of n terms


//fnd the sum of1+1/1!+1/2!..........+1/n!;
#include<iostream.h>
void main()
{
float t,sum;
int n,i;
cout<<"enter the value of n"<<endl;
cin>>n;
t=t+1;
t=1;
sum=1;
for(i=1;i<=n;i++)
{
while(n)
{
t=t*1/n;
--n;
}
sum+=t;
}
cout<<sum;
}