/* Euler  algorithm for first order differential equation */
/* dy/dt = -y(t), y(0)=1, 0<=t<=4, start h=0.5*/
#include <stdio.h>
 
#define dist 0.5                /* stepsize in t */
#define MAX 4.0                 /* max for t */ 
 
FILE *output;                   /* internal filename */

main()
{
double t, y;
int j;

output=fopen("euler.dat", "w"); /* external filename */

y=1;                            /* initial condition */
fprintf(output, "0\t%f\n", y);

for (j=1;dist*j<=MAX;j++)       /* the time loop */
{
   t=j*dist;
   y-=dist*y;
 
   fprintf (output, "%f\t%f\n", t, y);
}

fclose(output);
}