JWHooper
03-07-2008, 10:17 PM
I thought it was interesting to write C++ program for integral calculus application.
/* Calculates the area under the curve of y = x² from x = 0 to x = k,
where k > 0. */
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "Enter a positive real number: ";
double k;
cin >> k;
double integration = 0.5 * pow(k, 2.0);
cout << "The area under the curve is " << integration << "." << endl;
return 0;
}
/* Calculates the area under the curve of y = x² from x = 0 to x = k,
where k > 0. */
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "Enter a positive real number: ";
double k;
cin >> k;
double integration = 0.5 * pow(k, 2.0);
cout << "The area under the curve is " << integration << "." << endl;
return 0;
}