Program to find the Sum of Series | C++ Programming

Tuesday, August 11, 2020

//Program to find the Sum of Series

#include<iostream.h>

#include<stdio.h>

#include<conio.h>

void main()

{clrscr();

float x,sum,term,fact=1;

int i,n;

cout<<"\n enter the value of x and n:";

cin>>x>>n;

sum=1;term=1;

for(i=1;i<=n;i++)

{fact=fact*i;

term=term+(x/fact);

sum=sum+term;

}cout<<"\n sum of the series="<<sum;

getch();

}

Or

#include <iostream.h>

#include <conio.h>

#include <math.h>

void main()

{clrscr();

  long x,n,i,sum=0,term;

  cout<<"\n enter the x:";

  cin>>x;

  cout<<"\n enter the n:";

  cin>>n;

for(i=1;i<=n;i++)

 {

  term=pow(x,i);

  sum=sum+term;

 }

  cout<<"\n enter the sum="<<sum;

 getch();


 }

You Might Also Like

0 Comments

Like us on Facebook

Flickr Images

Flickr Short Films