#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
float fun(float x,float y)
{
return(x+fabs(sqrt(y)));
}
void main()
{
float y,x,h,e,k1,k2,k3,k4,k;
int n,i;
clrscr();
printf("\n enter the value of x0:");
scanf("%f",&x);
printf("\n enter the value of y0:");
scanf("%f",&y);
printf("\n enter step length h: ");
scanf("%f",&h);
printf("\n enter the vlaue of x at which y is needed :");
scanf("%f",&e);
n=(e-x)/h;
for(i=1;i<=n;i++)
{
printf("%d the iteration \n",i);
k1=h*fun(x,y);
k2=h*fun(x+h/2,y+k1/2);
k3=h*fun(x+h/2,y+k2/2);
k4=h*fun(x+h,y+k3);
k=(k1+2*k2+2*k3+k4)/6;
y=y+k;
x=x+h;
printf("\n the value of y at x=%f is %f",x,y);
}
getch();
}
#include<conio.h>
#include<math.h>
#include<stdlib.h>
float fun(float x,float y)
{
return(x+fabs(sqrt(y)));
}
void main()
{
float y,x,h,e,k1,k2,k3,k4,k;
int n,i;
clrscr();
printf("\n enter the value of x0:");
scanf("%f",&x);
printf("\n enter the value of y0:");
scanf("%f",&y);
printf("\n enter step length h: ");
scanf("%f",&h);
printf("\n enter the vlaue of x at which y is needed :");
scanf("%f",&e);
n=(e-x)/h;
for(i=1;i<=n;i++)
{
printf("%d the iteration \n",i);
k1=h*fun(x,y);
k2=h*fun(x+h/2,y+k1/2);
k3=h*fun(x+h/2,y+k2/2);
k4=h*fun(x+h,y+k3);
k=(k1+2*k2+2*k3+k4)/6;
y=y+k;
x=x+h;
printf("\n the value of y at x=%f is %f",x,y);
}
getch();
}
No comments:
Post a Comment