Lesson 14 of 18
Area Between Curves
Area Between Two Curves
The area between two curves and on is:
The absolute value handles the case where the curves cross (one is above the other at different points).
When Everywhere
If throughout , the area simplifies to:
Finding Intersection Points
To split the interval where the curves cross, find where — this is a root-finding problem.
Classic Example
Area between and on :
- on since
- Area
Numerically
Use the midpoint rule on :
for (int i = 0; i < n; i++) {
double x = a + (i + 0.5) * h;
double diff = f(x) - g(x);
sum += (diff < 0 ? -diff : diff); /* abs */
}
Your Task
Implement double area_between(double (*f)(double), double (*g)(double), double a, double b, int n) that returns .
TCC compiler loading...
Loading...
Click "Run" to execute your code.