(* This function will compute an approximate solution using Euler's Method.
n = number of steps
f = slope function *)
EulerMethod[xStart_,yStart_,xFinish_,n_,f_]:=
Module[{h,xCurrent,yCurrent,StepTable}, (* temporary variables *)
h=(xFinish-xStart)/n; (* Stepsize = h *)
xCurrent=xStart; 
yCurrent=yStart;
StepTable={{xStart,yStart}};
(* now the while-loop will crank through Euler's Method *) 
While[xCurrent<xFinish-h/2,
(* stepping forward in y: *)
yCurrent=yCurrent+h*(f/.{x->xCurrent,y->yCurrent}); 
(* stepping forward in x: *)
xCurrent=xCurrent+h;
StepTable = Join[StepTable,{{xCurrent,yCurrent}}];
];
StepTable (* returns the y-value at xFinish *)
];

(* Here's an example of y' = -y + cos(x), y(0) = 1, going up to x = 2 in 4 steps. *)
EulerMethod[0,1,2,4.0, -y+Cos[x]]

(* We can pick off the last value if we want: *)
EulerMethod[0,1,2,4.0, -y+Cos[x]][[-1]]