C Programming Blog

 
 
 
#include<stdio.h>
#include <math.h>
#include<conio.h>
//dy/dx = xy
#define F(x,y)  (x)*(y)
void main()
{
  double y1,y2,x1,a,n,h;
  int j;
  clrscr();
  printf(\"\\nEnter the value of range: \");
  scanf(\"%lf %lf\",&a,&n);
  printf(\"\\nEnter the value of y1: \");
  scanf(\"%lf\",&y1);
  printf(\"\\n\\nEnter the h: \");
  scanf(\"%lf\",&h);
  printf(\"\\n\\n  y1 = %.3lf \",y1);
  for(x1=a,j=2; x1<=n+h; x1=x1+h,j++)
  {
   y2= y1 + h * F(x1,y1);
   printf(\"\\n\\n  x = %.3lf => y%d = %.3lf \",x1,j,y2);
   y1=y2;
  }
getch();
}

/*
 OUT PUT
---------


Enter the value of range: 1 1.5

Enter the value of y1: 5


Enter the h: 0.1


  y1 = 5.000

  x = 1.000 => y2 = 5.500

  x = 1.100 => y3 = 6.105

  x = 1.200 => y4 = 6.838

  x = 1.300 => y5 = 7.726

  x = 1.400 => y6 = 8.808

  x = 1.500 => y7 = 10.129



*/

 
 
Didn't find what you were looking for? Find more on Program of EULERS METHOD