#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(x,y) 2*y/x
#define h 0.25
void main()
{
int i,n;
float x,x0,y0,m1,m2,m3,m4,y[10];
clrscr();
printf("\n Enter the inital value of x & y");
scanf("%f%f,&x0,&y0);
printf("Enter where you have to find y(x)");
scanf("%f",&x);
n=(x-x0)/h;
printf("%d",n);
for(i=1;i<=n;i++)
{
m1=f(x0,y0);
m2=f(x0+h/2,y0+m2*h/2);
m3=f(x0+h/2,y0+m2*h/2);
m4=f(x0+h,y0+m3*h);
y[i]=y0+(m1+2*m2+2*m3+m4)*n/6;
x0=x0+h;
y0=y[i];
}
printf("\n The value of f(x) at x=%f",y0);
getch();
}
No comments:
Post a Comment