implicit none integer i,n real a,b,h,x,y,xl,yl,f real yp,k1,y0 real err,exact character char*11 print*,' Enter number of intervals n' read(5,*) n print*,' Enter a,b,y(a)' read(5,*) a,b,y0 h=(b-a)/float(n) 100 continue y=y0 x=a write(6,30) x,y 30 format(/,' Solving with Euler Method gives:',/, & ' X Y exact %error', & /,1x,f5.3,1x,f10.6,1x,f10.6) do i=1,n xl=x yl=y k1=h*f(xl,yl) x=xl+h y=yl+k1 exact=2.0*sin(x)*sin(x)+3.*x if(abs(exact).gt.1.e-6) then err=100.0*(y-exact)/exact write(6,2) x,y,exact,err else char='div by zero' write(6,3) x,y,exact,char endif enddo 2 format(1x,f6.3,1x,f10.6,1x,f10.6,1x,f10.6) 3 format(1x,f6.3,1x,f10.6,1x,f10.6,2x,a11) stop end real function f(x,y) implicit none real x,y f=4.0*sin(x)*cos(x)+3.0 return end