شما این محصولات را انتخاب کرده اید

سبد خرید

برنامه محاسبه انتگرال در زبان C++
شناسه پست: 1304
بازدید: 1801

برنامه محاسبه انتگرال در زبان C++

				
					#include<iostream>
#include<math.h>
#include<stdio.h>
#include<conio.h>
using namespace std;

double integral(double(*f)(double x), double(*g)(double x, double y), double a, double b, int n)
{
    double step = (b - a)/n;   // width of rectangle
    double area = 0.0;
    double y = 0;  // height of rectangle

    for(int i = 0; i < n; ++i)
    {
        y = f(a + (i + 0.5) * step) * g(a + (i + 0.5) * step, y);
        area += y * step; 
        // find the area of the rectangle and add it to the previous area. Effectively summing up the area under the curve.
    }

    return area;
}

// To call:

int main()
{
    int x = 3;
    int low_end;
    cout<<"please inter low_end:\n";
    cin >> low_end;
    int high_end;
    cout<<"please inter high_end:\n";
    cin>>high_end;
    high_end*=M_PI;
    int steps;
    cout<<"how many steps:\n";
    cin>>steps;
    cout << integral(powf, cosf, low_end, high_end, steps);
    return 0;
}
				
			

توضیحات:

صورت سوال:

برنامه محاسبه انتگرال در سی پلاس پلاس

اشتراک در
اطلاع از
guest

0 نظرات
قدیمی‌ترین
تازه‌ترین بیشترین رأی
بازخورد (Feedback) های اینلاین
مشاهده همه دیدگاه ها