RSS

Category Archives: Series

SERIES 3

/* THIS PROGRAM CREATES A FUNCTION TO FIND THE SUM OF THE FOLLOWING SERIES
Y + Y ^3/2! + Y^5 /3! + … + Y^(2m-1)/m!  */

#include <iostream.h>
#include <conio.h>
#include <math.h>

double sumseries(int,int);

void main()
{
clrscr();
int y,m;
cout<<“Enter the Value of ‘Y’\n”;
cin>>y;
cout<<“\nEnter the number of terms\n”;
cin>>m;
double sum = sumseries(y,m);
cout<<“\nThe sum of the series is \n”<<sum;
getch();
}

double sumseries(int y, int m)
{
double sum = 0.0;

for(int i=1; i<=m; i++)
{
int val = 1;
int k =i;
while(k>0)
{
val *= k;
k–;
}
sum += pow(y,i)/val;
}

return sum;
}

 
Leave a comment

Posted by on June 28, 2015 in Series

 

SERIES 2

/* THIS PROGRAM PRINTS THE SUM OF THE FOLLOWING SERIES
X – X^2 /2! + X^4 /4! – X ^6/6! + X^8 /8! – …. X    / (2n-2)!  */

#include <iostream.h>
#include <conio.h>

double pow(float,int);
long fact(int);

void main()
{
clrscr();
float sum = 0.0,x;
int nterms,sign = -1;
cout<<“Enter the value of ‘x’\n”;
cin>>x;
cout<<“Enter the number of terms\n”;
cin>>nterms;

for(int i=1; i<nterms; i++)
{
if((2*i) % 4 == 0)
sign = 1;
else
sign = -1;
sum += sign * (pow(x,2*i)/fact(2*i));
}

cout<<“\nThe Sum of the Series is \n”<<x + sum;
getch();
}

double pow(float num, int power)
{
float val = 1.0;

for(int i=0; i<power; i++)
{
val = val*num;
}
return val;
}

long fact(int num)
{
long val = 1;

while(num>0)
{
val = val*num;
num–;
}
return val;
}

 
Leave a comment

Posted by on June 28, 2015 in Series

 

SERIES 1

/* THIS PROGRAM FINDS THE SUM OF THE FOLLOWING SERIES

x – x^2/2! + x^3/3! -x^4/4! + …. x^n/n!    */

#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <iomanip.h>

int fact(int num);

void main()
{
clrscr();
int x,range, sign=1;
float sum=0.0, val = 0.0;

cout<<“Enter the value of x\n”;
cin>>x;
cout<<“\nEnter the number of terms\n”;
cin>>range;
cout<<‘\n’;

for(int i=1; i<=range; i++)
{
if(i%2 == 0)
sign = -1;
else
sign = 1;

val = sign * (pow(x,i)/fact(i));
sum += val;
}

cout<<“The result is “<<setprecision(2)<<sum;
getch();

}

int fact(int num)
{
int val = 1;

while(num>0)
{
val *= num;
num–;
}

return val;
}

 
Leave a comment

Posted by on June 28, 2015 in Series