// Arup Guha
// 3/14/2012

#include <stdio.h>

#define N 4

double f(double t, double y);

int main() {

    double w[N+1];

    // Given in the problem.
    double a = 0, b = 2;
    w[0] = 0.5;

    double h = (b - a)/N;
    int i;

    // Do Euler's Method here.
    for (i=1; i<=N; i++) {
        w[i] = w[i-1] + h*f(a+(i-1)*h, w[i-1]);
    }

    // Print out the results.
    for (i=0; i<=N; i++) {
        printf("%lf\t%lf\n", a+i*h, w[i]);
    }

    return 0;
}

// Example #1 (ppg 266-7)from the textbook.
double f(double t, double y) {
    return y - t*t + 1;
}
