1.

Write programs to find the sum of the following series:(a)  X - \(\frac{x^2}{2!}\) + \(\frac{x^3}{3!}\) + \(\frac{x^4}{4!}\) + \(\frac{x^5}{5!}\) + \(\frac{x^6}{6!}\)(b) X + \(\frac{x^2}{2}\) + \(\frac{x^3}{3}\) + ..... + \(\frac{x^n}{n}\)

Answer»

(a) # include <iostream>

using namespace std;

# include <math.h>

# factorial function

long int fact (int n)

{

long int f = 1;

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

f* = i;

return f;

}

// main function

int main()

{

int x,y = 1;

float sum = 0;

cout <<"Enter the value for x:";

cin>>x;

for(int i = 1; i<=6; i++)

{

sum = sum + y*((pow(x,1))/fact(i));

y* = -1;

}

cout <<"Sum = "<<Sun<<end1;

cin.get();

return();

}

(b) # include

using namespace std;

# include int main()

{

int M, L;

float sum = 0;

cout > M;

cout << “Enter the number of terms”; cin>>M;

cout << “Enter the number of terms”; cin>>L;

for (int i = 1; i<=m; i++)

sum = Sum + Pow(m,i)/i;

cout <<“Sum= ” << Sum <<end1;

cin.get();

return 0;

}



Discussion

No Comment Found