Write a program that takes a value x as input and outputs this sum for n taken to be each of the values 1 to 100. The program should also output ex calculated using the predefined function exp. The function exp is a predefined function such that exp(x) returns an approximation to the value ex. The function exp is in the library with the header file cmath. Your program should repeat the calculation for new values of x until the user says she or he is through

Respuesta :

Explanation:

#include <iostream.h>

#include <conio.h>

#include <math.h>

main ()

{

     int x;

     double sum, fact;

     char ans;

     do

     {

           cout << "Please enter the value x: ";

           cin >> x;

           cout << endl;

           sum = fact = 1;

 

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

           {

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

                 {

                   fact = n*fact;

                        }

             sum += (pow(x,n)/fact);

                       

        cout <<"n = "<<n<<" and sum = "<< sum << " and

        exp("<<x<<") = "<<exp(x)<<endl;

                }

        cout << endl;

       cout << "Do you want to calculate this again? (y/n): ";

        cin >> ans;

 } while (ans == 'y' || ans == 'Y');

getch ();

}

RELAXING NOICE
Relax