Please solve using code not on paper doesnt matter which pro

Please solve using code not on paper doesn\'t matter which program you use c++ or anything. Show all work and output. Use for loop. This is all the information I have to solve it.

Solution

#include <iostream>

#include <cmath>

using namespace std;

main(){

    int a,b,n;

    cout << \"Enter upper limit, b:\"; cin >> b;

    cout << \"Enter lower limit, a:\"; cin >> a;

    cout << \"\ Enter number of Simpson\'s interval, n (even number only):\"; cin >> n;

    long double dx, t=0;

    dx = (long double)(b-a)/n;

    long double fx[n+1];

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

        if (i == 0){

            t = a;

        }

        else if (i == n){

            t = b;

        }

        else{

            t = a+(i*dx);

        }

        //cout << \"t = \" << t << endl; // im just curious to know

        fx[i] = (1.36*pow(10,-10))*t*t*t*t - (1.23*pow(10,-7))*t*t*t + (4.12*pow(10,-6))*t*t + (3.95*pow(10,-4))*t - (8.58*pow(10,-2));

        //fx[i] = (double)1 / (t + 1 );

        //cout << \"fx[\" << i << \"] = \" << fx[i] << endl; // im just curious to know

    }

    long double sum = 0, area = 0;

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

            if (i == 0 || i == n){

                sum = sum + fx[i];

            }

            else if( i%2 == 0){

                sum = sum + 2*fx[i];

            }

            else {

                sum = sum + 4*fx[i];

            }

    }

    area = (dx/3)*sum;

    cout << \"sum = \" << sum << endl;

    cout << \"dx = \" << dx << endl;

    cout << \"\ The Area is = \" << area << endl;

    return 0;

}

 Please solve using code not on paper doesn\'t matter which program you use c++ or anything. Show all work and output. Use for loop. This is all the information
 Please solve using code not on paper doesn\'t matter which program you use c++ or anything. Show all work and output. Use for loop. This is all the information

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site