12. Write a program to demonstrate Euler's Method.
/* Program to execte Euler's Method*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
float dif ( float x,float y )
{
return x+y;
}
void main()
{
float x ,h,x0,x1,y0,y1;
printf("Enter the values of x,h,x0,y0: ");
scanf("%f%f%f%f", &x, &h, &x0,&y0);
x1=x0;
y1=y0;
while(x1 < x) {
y1 += h*dif(x1,y1);
x1 += h;
printf("\n Values of y=%f, when x=%f",y1,x1);
}
getch();
}
Output
Enter the values of x,h,x0,y0: 1 0.1 0 1
Values of y=1.100000, when x=0.100000
Values of y=1.220000, when x=0.200000
Values of y=1.362000, when x=0.300000
Values of y=1.528200, when x=0.400000
Values of y=1.721020, when x=0.500000
Values of y=1.943122, when x=0.600000
Values of y=2.197434, when x=0.700000
Values of y=2.487178, when x=0.800000
Values of y=2.815895, when x=0.900000
Values of y=3.187485, when x=1.000000