/****************************************************************/
/* Module : euler.c 						*/
/* Section: 10.1						*/
/* Cheney-Kincaid, Numerical Mathematics and Computing, 5th ed, */
/* Brooks/Cole Publ. Co.                                        */
/* Copyright (c) 2003.  All rights reserved.                    */
/* For educational use with the Cheney-Kincaid textbook.        */
/* Absolutely no warranty implied or expressed.                 */   
/* 								*/
/* Description: Euler's method  				*/
/*								*/
/****************************************************************/

#include <stdio.h>
#include <stdlib.h>

float f(float t, float x); /*define prototype */

float f(float t, float x)
{
  return(1 + x * x + t * t * t);
}


void main()
{
  const int n = 100;
  const float a = 1.0, b = 2.0;
  int k;
  float h,t, x = -4.0;

  h = (b - a) / n;
  t = a;
  printf("0 t = %f x = %f\n", t, x);

  for (k = 1; k <= n; k++)
  {
    x += h * f(t, x);
    t += h;
    printf("k = %d t = %f x = %f\n", k, t, x);
  }
}









