``````/***************************************************
Integration of f(x) by simple end-point approximation

Write a program that will approximate the integral of

f(x) = 2/sqrt(1-x^2)

The bounds of integration should be supplied by the
user, as well as the number of rectangles used in the
approximation.

Note:  The integral f(x) from 0 to 1 has a value
you should recognize!

Note:  You could change the function by changing a
single line in the code, in case you want to
approximate a different integral.
***************************************************/
#include "si204.h"
#include <math.h>

int main() {
fputs("Enter integration bounds a and b: ", stdout);

fputs("Enter n, the number of steps: ", stdout);

// Compute width of rectangles
double w = (b - a) / n;

// Initialize integral approximation value to zero
double approx = 0.0;

// update approximation from each step
for(int i=0; i < n; i++) {
// Compute evaluation point x
double x = a + i*w;

// Compute fucntion value at x
// XXX: change this line to compute a different integral!
double fx = 2.0 / sqrt(1.0 - x*x);

// Add area of rectangle to approx
approx += fx * w;
}