#include #include #define PI 3.14159 const float range_bottom = PI / 2; const float range_top = 2 * PI / 3; const float intervals = 100000; float f(float x) { return (1 / sin(x)); } int main(void) { float oversum, undersum, average, steps; steps = (range_top - range_bottom) / intervals; for(float i = range_bottom; i <= range_top; i += steps) { oversum += steps * f(i); undersum += steps * f(i - steps); } average = (oversum + undersum) / 2; printf("Area under f(x) between %f and %f:\n", range_bottom, range_top); printf("%f\n", average); printf("Interval: %f\n", steps); }