C program that computes the value of ex using a formula

Home Forums C Programming C program that computes the value of ex using a formula

This topic contains 2 replies, has 2 voices, and was last updated by  SilviaJamieson 8 years, 11 months ago.

  • Author
    Posts
  • #2170

    Help please with program, I seem to have blocks when it comes to anything that has an equation in it!

    Write a C program that computes the value of ex by using the following formula.

    e^x = 1 + x/(1!) + x^2/(2!) + x^3/(3!)+…x^n/(n!)

    – The program should ask user to input value of x and number of terms (n) to approximate value of ex
    – Then it calculates and displays the approximated value of the result
    – Compare the approximated value of ex with the C library function exp() and find the absolute [use fabs()]difference between the two.

    An example of input/output dialog is shown below:-

    Enter value of x : 2
    Enter number of terms (n) : 18
    The approximated value of ex : 7.389056098885
    The value of ex using C library function : 7.389056098931
    The absolute difference between the two value :
    0.000000000046

    Many thanks, daisy…..

  • #3501

    try:

    I didn’t know how many digit to output so I chose 12 like the example. You can change this by changing the number listed after the ‘.’ in the last printf() statements.

    Theres an error in the code I posted for the approximation of e = 1 + 1/1! + 1/2! . Heres the proper code:

  • #3502

    Thanks dman, and for the correction to the other code. I am trying to learn computer programming at home and you are making it so much easier to understand, for that i am very grateful.

    daisy….

You must be logged in to reply to this topic.

0 Shares
Share
+1
Tweet
Share
Stumble