Euler Method in C

Euler's Method is a form of numerical integration — a way to approximate the solution of a first-order differential equation where the initial point on the solution curve is known, but the shape of the curve is unknown.

Program of Euler in c


  #include<stdio.h>
  #include<conio.h>
  #include<math.h>
  float f(float x, float y)
  {
  float a;
  a=x*y;
  return a;
  }

  void main()
  {
    int n,i,test;
    float x,xf,y,y1,h;
    clrscr();
    printf("Enter the First value :- ");
    scanf("%d",&x);
    printf("Enter the Second value :- ");
    scanf("%d",&xf);
    printf("Enter the Lenth y :- ");
    scanf("%d",&y);
    printf("Enter the Width h :- ");
    scanf("%d",&h);
    while(x<xf)
    {
        y1=y+h*f(x,y);
        x=x+h;
        y=y1;
    }
    printf("Output = %f",y1);
    
    getch();
  }
  

Output

Enter the First value :- 1
Enter the Second value :- 3
Enter the Lenth y :- 6
Enter the Width h :- 3
Output :- 0.000000

Post Your Comment