Sie sind auf Seite 1von 4

1.

Homework

program try

real::a,b,sq,c,fact

call input(a,b) !calls function for getting input

if (a==1) then

call squaring(a,b,sq) !calls function for squaring the number

end if

if (a==2) then

call cube(a,b,c) !calls function for cubing the


number

end if

if (a==3) then

call factorial(a,b,fact) !calls function for finding the factorial of the


number

end if

end program try

subroutine input(a,b) !for getting input

print*,"Enter the number"

read*,a

print*,"Enter 1 for squaring the number"

print*,"Enter 2 for finding cube of the number"

print*,"Enter 3 for finding factorial of the number"

read*,b

end subroutine

subroutine squaring(a,b,sq) !for squaring

sq=a**2

print*,"The square of the number is",sq

end subroutine
subroutine cube(a,b,c) !for cubing
the number

c=a**3

print*,"The cube of the number is",c

end subroutine

subroutine factorial(a,b,fact) !for finding factorial

integer::n

fact=1

do n=1,a

fact=fact*n

end do

print*,"The factorial of the number is",fact

end subroutine

2.runge kutta

program runge
real::h,x0,y0,w1,w2,w3,w4,w !variable type

print*,"enter the value of the h" !display to enter the value of h


read*,h
print*,"enter the value of x0 " !display to enter the value of x0
read*,x0
print*,"enter the value of x0 " !display to enter the value of y0
read*,y0
w1=h*2*x0*y0 !formula for calculating values
w2=h*2*(x0+h/2)*(y0+w1/2)
w3=h*2*(x0+h/2)*(y0+w2/2)
w4=h*2*(x0+h)*(y0+w3)
w=y0+(w1+2*w2+2*w3+w4)/6
print*,"The value of w1 is",w1
print*,"The value of w2 is",w2
print*,"The value of w3 is",w3
print*,"The value of w4 is",w4
print*,"The value of approximate solution is",w !output
end program runge

3. program runge
real::h,x0,y0,w1,w2,w3,w4,w
CALL input(h,x0,y0) ! calls the module for getting input
call values(h,x0,y0,w1,w2,w3,w4,w) ! calls the values
end program runge

subroutine input(h,x0,y0) !getting input values


print*,"enter the value of the h"
read*,h
print*,"enter the value of X0 "
read*,x0
print*,"enter the value of Y0 "
read*,y0
end subroutine
subroutine values(h,x0,y0,w1,w2,w3,w4,w)
w1=h*2*x0*y0
w2=h*2*(x0+h/2)*(y0+w1/2)
w3=h*2*(x0+h/2)*(y0+w2/2)
w4=h*2*(x0+h)*(y0+w3)
w=y0+(w1+2*w2+2*w3+w4)/6
print*,"The value of w1 is",w1
print*,"The value of w2 is",w2
print*,"The value of w3 is",w3
print*,"The value of w4 is",w4
print*,"The value of approximate solution is",w
end subroutine

Das könnte Ihnen auch gefallen