Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- start
- input x,y,h,xf, initial values, size and required values
- while loop until (x<xf)
- s1 = f(x,y);
- s2 = f(x+h,y+(h*s1));
- s = (s1+s2)/2;
- y = y+ (h*s);
- x = x+h;
- end while loop
- display output y
- stop
- // Online C compiler to run C program online
- #include <stdio.h>
- #include<math.h>
- #define f(x,y) (x+y)
- int main() {
- int n,i;
- float x0,y0,xn,h,s,s1,s2;
- printf("Enter the x0,y0,h & xn\n");
- scanf("%f %f %f %f",&x0,&y0,&h,&xn);
- while(x0<xn){
- s1 = f(x0,y0);
- s2 = f(x0+h,y0+(h*s1));
- s = (s1+s2)/2;
- y0 = y0+ (h*s);
- x0 = x0 + h;
- printf("\ny(%f) = %f",x0,y0);
- }
- printf("\n\nFinal Output y(%f) = %f",x0,y0);
- }
- Enter the x0,y0,h & xn
- 0 1 0.1 0.4
- y(0.100000) = 1.110000
- y(0.200000) = 1.242050
- y(0.300000) = 1.398465
- y(0.400000) = 1.581804
- Final Output y(0.400000) = 1.581804
- /*
- Enter the first and second value
- 1 2
- Enter the length and required result
- 0.2 1.4
- x0 y0 s1 s2 s
- 1.200000 2.680000 3.000000 3.800000 3.400000
- 1.400000 3.553600 3.880000 4.856000 4.368000
- Output is 3.553600
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement