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

Viewing 2 reply threads
  • Author
    Posts
    • #2170
      SilviaJamieson
      Participant

      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
      GWILouisaxwzkla
      Participant

      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
      SilviaJamieson
      Participant

      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….

Viewing 2 reply threads
  • You must be logged in to reply to this topic.