Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // program
- #include<stdio.h>
- #define f(x,y) (y-x)/(y+x)
- int main(){
- float x0,y0,h,xn,x,y;
- int n;
- printf("Enter values x0, y0, h and xn \n");
- scanf("%f %f %f %f",&x0,&y0,&h,&xn);
- n = (xn-x0)/h;
- for(int i=1 ; i<=n ; i++){
- printf("\nvalues of x0 = %f & y0 = %f",x0,y0);
- y = y0 + (h*f(x0,y0));
- x = x0 + h;
- if(x<xn){
- x0 = x;
- y0 = y;
- }
- else
- break;
- }
- printf("\nOutput x = %f and y = %f",x,y);
- return 0;
- }
- /*
- Ouput
- Enter values x0, y0, h and xn
- 0 1 0.02 0.1
- values of x0 = 0.000000 & y0 = 1.000000
- values of x0 = 0.020000 & y0 = 1.020000
- values of x0 = 0.040000 & y0 = 1.039231
- values of x0 = 0.060000 & y0 = 1.057748
- values of x0 = 0.080000 & y0 = 1.075601
- Output x = 0.100000 and y = 1.092832
- */
- // Algorithm
- start
- define function // define f(x,y) x*typede
- Get the values of x0,y0,h and xn
- *Here x0 and y0 are the initial conditions
- h is the interval
- xn is the requred value
- // x0= 0 y0=1 , h=0.1 , xn=0.4
- n=(xn-x0)/h // n=(0.4-0)/0.1 = 4
- start loop from i =1 to n
- Print values of y0 and x0 // 1,0 // 1,0.1 // 1,0.1,0.2 // 1.0302,-.0302
- y=y0 + h*f(x0,y0)//1.061106
- x=x0+h//0.4
- check if x<xn // 0.4<0.4.4
- if yes
- then
- x0 = x
- y0 = y
- if no goto 10
- End loop i
- Print x and y
- Stop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement