Question:

Sum=1-4+u pow(4)/(2!)-u (pow6)/(3!)+u (pow8)/(4!)-......+(-1) (pow8) u (pow2n)/(n!)?

by  |  earlier

0 LIKES UnLike

can some body please help me program this in c++ where pow means power or raised to! thank you very very much!

 Tags:

   Report

1 ANSWERS


  1. #include <iostream>

    using namespace std;

    int

    factorial (int x) {

         for (int n = x-1; n > 1; n--) {

              x = x * n;

         }

    return x;

    }

    int

    pow (int x, int y) {

    int z = 1;

         for (; y > 0; y--) {

              z = z * x;

         }

    return z;

    }

    int

    formula(int n, int u) {

         int sum = -3

         for (int i = 2, i <= n; i++) {

              sum = sum + pow(u, i*2) / factorial (i);

         }

    return sum;

    }

    int main( int argc, char **argv )

    {

        int answer = formula (5, 4);

        cout << "The answer is" << answer << "\n";

    return 0;

    }

    Note that there will be bugs in this answer because I haven't tested it and I wasn't sure of your formula, but it should be a good exercise to finish it off, I've given you a start. You'll need to test the pow and factorial functions individually at first, then test the formula function. You can do this by calling the from the main function and using cout to print the results to screen, as you should know.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.