You are on page 1of 20

SOLUTION TO EXCERCISES

2.1)
PROGRAM temp_conversion
IMPLICIT NONE
REAL::F,C
PRINT*,"ENTER VALUE OF F"
READ*,F
PRINT*,"F =",F
C=(F-32.0)*5/9
PRINT*,"Celsius=",C
END PROGRAM temp_conversion

2.2)
! To convert yard to feet and inch
PROGRAM yard_feet
IMPLICIT NONE
REAL::yard,feet,inch
PRINT*,"Enter value of yard = "
READ*,yard
PRINT*,"Yard = ",yard
feet= 3.0*yard
inch= 12.0*feet
PRINT*,"Feet = ",feet,"Inch = ",inch
END PROGRAM yard_feet

2.3)
PROGRAM pound_kilogram
IMPLICIT NONE
REAL::pound,kilogram
PRINT*,"Enter value of pound = "
READ*,pound
PRINT*,"Pound = ",pound
kilogram=pound/2.205
PRINT*,"Kilogram = ",kilogram
END PROGRAM pound_kilogram

2.4)
PROGRAM area_perimeter
IMPLICIT NONE
REAL:: radius,area,perimeter
PRINT*,"Enter value of radius = "
READ*,radius
Print*,"Rdius = ",radius
area =3.14*(radius**2.0)
perimeter=2.0*3.14*radius
PRINT*,"Area = ",area,"Perimeter = ",perimeter
END PROGRAM area_perimeter

2.5)
PROGRAM millimeter_conversion
IMPLICIT NONE
REAL::millimeter,meter,centimeter
PRINT*,"Enter value in millimeter = "
READ*,millimeter
meter=0.001*millimeter
centimeter=0.1*millimeter
PRINT*,"In meter = ",meter,"In centimeter = ",centimeter
END PROGRAM millimeter_conversion

4.7)
! Evaluating expressions w=a/s*(s-a) , x=w*a , t=x/s**(-a)
PROGRAM evaluate_w_x_t
IMPLICIT NONE
REAL:: a,s,w,x,t
PRINT*,"Enter values of a and s"
READ*,a,s
w=a/(s*(s-a))
x=w*a
t=x/(s**(-a))
PRINT*,"w,x,t=",w,x,t
END PROGRAM evaluate_w_x_t

4.8)
! Evaluating 0.0092*2*a*log10(((4*a**2)/b)/(a*sqrt(2-L)))+0.004*(a*(a*sqrt(2-
L))+0.45*b)
! Substituting a=15.2,b=10.2,L=1.2
PROGRAM calculate_T
IMPLICIT NONE
REAL::a,b,L,T
PRINT*,"Enter values of a,b,L"
READ*,a,b,L
T=0.0092*2*a*log10(((4*a**2)/b)/(a*sqrt(2-L)))+0.004*(a*(a*sqrt(2-L))+0.45*b)
PRINT*,"T=",T
END PROGRAM calculate_T

4.9)
PROGRAM reverse
IMPLICIT NONE
INTEGER::d1,d2,d3,d4,d5,n,rev
PRINT*,"Enter a five digit number"
read*,n
d1=MOD(n,10)
n=n/10
d2=MOD(n,10)
n=n/10
d3=MOD(n,10)
n=n/10
d4=MOD(n,10)
n=n/10
d5=n
rev=d1*10**4+d2*10**3+d3*10**2+d4*10+d5
PRINT*,"Reverse=",rev
END PROGRAM reverse

4.10)
PROGRAM calcu_g1_g2
IMPLICIT NONE
REAL::a,b,c,d,e,f,g1,g2
PRINT*,"Enter values of a,b,c,d,e,f"
READ*,a,b,c,d,e,f
g1=(a*b)/(c*d+e)+f
g2=a/(b*c)-d
PRINT*,"g1=",g1
PRINT*,"g2=",g2
END PROGRAM calcu_g1_g2

4.11) (a)
PROGRAM simple_interest
IMPLICIT NONE
REAL::p,r,t,a
PRINT*,"Enter values of principal amount,rate of interest per annum,tenure"
READ*,p,r,t
a=p+(p*r*t/100)
PRINT*,"Final amount=",a
END PROGRAM simple_interest
4.11) (b)
PROGRAM compound_interest
IMPLICIT NONE
REAL::p,r,t,a
PRINT*,"Enter values of principal amount,rate of interest per annum,tenure"
READ*,p,r,t
a=p*(1+(r/100))**t
PRINT*,"Final amount=",a
END PROGRAM compound_interest

4.11) (c)
PROGRAM compound_interest
IMPLICIT NONE
REAL::p,r,t,k,a
PRINT*,"Enter values of principal amount,rate of interest per annum,k value"
READ*,p,r,t,k
a=p*((1+(r/(100*k)))**(k*t))
PRINT*,"Final amount=",a
END PROGRAM compound_interest

4.12)
PROGRAM temp_conversion
IMPLICIT NONE
REAL::F,C
PRINT*,"ENTER VALUE OF F"
READ*,F
PRINT*,"F =",F
C=(F-32.0)*5/9
PRINT*,"Celsius=",C
END PROGRAM temp_conversion
4.13)
PROGRAM pound_kilogram
IMPLICIT NONE
REAL::pound,kilogram
PRINT*,"Enter value of pound = "
READ*,pound
PRINT*,"Pound = ",pound
kilogram=pound/2.205
PRINT*,"Kilogram = ",kilogram
END PROGRAM pound_kilogram

4.14)
PROGRAM pound_rupees
IMPLICIT NONE
REAL::pound,rupees
PRINT*,"Enter value of pound = "
READ*,pound
rupees=pound*47.85*100
PRINT*,"Value in paisa =",rupees
END PROGRAM pound_rupees

4.15)
PROGRAM millimeter_conversion
IMPLICIT NONE
REAL::millimeter,meter,centimeter
PRINT*,"Enter value in millimeter = "
READ*,millimeter
meter=0.001*millimeter
centimeter=0.1*millimeter
PRINT*,"In meter = ",meter,"In centimeter = ",centimeter
END PROGRAM millimeter_conversion
4.16)
PROGRAM area_perimeter
IMPLICIT NONE
REAL:: radius,area,perimeter
PRINT*,"Enter value of radius = "
READ*,radius
Print*,"Rdius = ",radius
area =3.14*(radius**2.0)
perimeter=2.0*3.14*radius
PRINT*,"Area = ",area,"Perimeter = ",perimeter
END PROGRAM area_perimeter

4.17)
PROGRAM area_triangle
IMPLICIT NONE
REAL::a,b,c,s,area
PRINT*,"Enter the value os sides a,b,c="
READ*,a,b,c
s=(a+b+c)/2
area=sqrt(s*(s-a)*(s-b)*(s-c))
PRINT*,"Area of triangle=",area
END PROGRAM area_triangle

4.18)
PROGRAM magnitude_argument
IMPLICIT NONE
REAL::x,y,r,z
PRINT*,"Enter values of x and y"
READ*,x,y
r=SQRT(x**2+y**2)
z=(ATAN(y/x))*(180/3.14)
PRINT*,"Magnitude,argument=",r,z
END PROGRAM magnitude_argument

6.1)
PROGRAM xy_coordinate
IMPLICIT NONE
REAL::x,y
PRINT *,"Enter (x,y)"
READ*,x,y
IF((x==0).and.(y==0)) THEN
PRINT*,"The point lies on origin"
ELSE IF((x/=0).and.(y==0)) THEN
PRINT*,"The point lies on x axis"
ELSE IF((x==0).and.(y/=0)) THEN
PRINT*,"The point lie on y axis"
ELSE
PRINT*,"The point lies neither on the x nor the y axis"
ENDIF
END PROGRAM xy_coordinate

6.2)
PROGRAM xy_quadrant
IMPLICIT NONE
REAL::x,y
PRINT *,"Enter (x,y)"
READ*,x,y
IF((x>0).and.(y>0)) THEN
PRINT*,"The point lies in First quadrant"
ELSE IF((x<0).and.(y>0)) THEN
PRINT*,"The point lies in Second quadrant"
ELSE IF((x<0).and.(y<0)) THEN
PRINT*,"The point lies in Third quadrant"
ELSE IF((x>0).and.(y<0)) THEN
PRINT*,"The point lies in fourth quadrant"
ELSE
PRINT*,"The point lies on origin"
ENDIF
END PROGRAM xy_quadrant

6.3)
PROGRAM circle_point
IMPLICIT NONE
REAL::x,y,d,r
PRINT*,"Enter the radius"
READ*,r
PRINT*,"Enter the coordinates"
READ*,x,y
d=SQRT(x**2+y**2)
IF (d<r) THEN
PRINT*,"Point lies inside circle"
ELSE
PRINT*,"Point lies outside circle"
ENDIF
END PROGRAM circle_point

6.4)
PROGRAM leap_year
IMPLICIT NONE
INTEGER::N
PRINT*,"Enter the year ="
READ*,N
IF (((MOD(N,100)==0).and.(MOD(N,400)==0)).or.((MOD(N,100)/=0).and.(MOD(N,4)==0)))
THEN
PRINT*,"Its a leap year"
ELSE
PRINT*,"Its not a lep year"
ENDIF
END PROGRAM leap_year

6.5)
PROGRAM rectangle
IMPLICIT NONE
REAL::l,b,a,p
PRINT*,"Enter values of length and breadth"
Read*,l,b
a=l*b
p=2*(l+b)
IF (a>p) THEN
PRINT*,"Area is greater then perimeter"
ELSE
PRINT*,"Area is less then perimeter"
ENDIF
END PROGRAM rectangle

6.6)
PROGRAM isoceles
IMPLICIT NONE
REAL::a,b,c
PRINT*,"Enter value of a,b,c"
READ*,a,b,c
IF((a==b).or.(b==c).or.(c==a)) THEN
PRINT*,"Its isoceles trinagle"
ELSE
PRINT*,"Its not an isoceles trinagle"
ENDIF
END PROGRAM isosceles

6.7)
PROGRAM collinear
IMPLICIT NONE
REAL::x1,y1,x2,y2,x3,y3,r
PRINT*,"ENTER (x1,y1),(x2,y2),(x3,y3)"
READ*,x1,y1,x2,y2,x3,y3
r=0.5*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))
IF(r==0) THEN
PRINT*,"Points are collinear"
ELSE
PRINT*,"Points are not collinear"
ENDIF
END PROGRAM collinear

6.8)
PROGRAM ascending
IMPLICIT NONE
INTEGER::a,b,c
PRINT*,"Enter values of a,b,c"
READ*,a,b,c
IF(a<b) THEN
IF(a<c) THEN
IF(b<c) THEN
PRINT*,a,b,c
ELSE
PRINT*,a,c,b
ENDIF
ELSE
PRINT*,c,a,b
ENDIF
ELSE
IF(b<c) THEN
IF(a<c) THEN
PRINT*,b,a,c
ELSE
PRINT*,b,c,a
ENDIF
ELSE
PRINT*,c,b,a
ENDIF
ENDIF
END PROGRAM ascending

6.9)
PROGRAM roundoff
IMPLICIT NONE
REAL::n
10 format(f4.2)
PRINT*,"Enter a decimal number between 1 and 2"
READ*,n
print 10,n
END PROGRAM roundoff

6.10)
PROGRAM deposit
IMPLICIT NONE
REAL::p,t,i,a,n
PRINT*,"Enter the principal amount and duration of deposit in years"
READ*,p,t
IF((p<10000).and.(t>=2).and.(t<5)) THEN
i=15
ELSE IF((p>=10000).and.(p<15000).and.(t>=2).and.(t<5)) THEN
i=16
ELSE IF((p>=15000).and.(t>=1).and.(t<5)) THEN
i=17
ELSE IF (t>=5) THEN
i=18
ELSE
i=10
ENDIF
a=p*((1+(i/100))**t)
n=a-p
PRINT*,"Principal amount",p
PRINT*,"Tenure in years ",t
PRINT*,"Rate of interest",i
PRINT*,"Total interest credited",n
PRINT*,"Total amount",a
END PROGRAM deposit

7.1)
PROGRAM rev_order
IMPLICIT NONE
INTEGER::n,d,s=0
PRINT*,"Type the number"
READ*,n
DO
IF(n==0) EXIT
d=MOD(n,10)
n=n/10
s=s*10+d
END DO
PRINT*,"Reverse",s
END PROGRAM rev_order

7.2)
PROGRAM palindrome
IMPLICIT NONE
INTEGER::n,d,s=0,k
PRINT*,"Type the number"
READ*,n
k=n
DO
IF(n==0) EXIT
d=MOD(n,10)
n=n/10
s=s*10+d
END DO
IF(k==s) THEN
PRINT*,"ITS A PALINDROME"
ELSE
PRINT*,"ITS NOT A PALINDROME"
ENDIF
END PROGRAM palindrome

7.3)
! To convert octal to decimal
PROGRAM octal _decimal
IMPLICIT NONE
INTEGER::x,n,a,r=0
PRINT *,”Enter octal number”
READ *,n
PRINT *,”Octal number=”,n
DO x=0,n-1
a=mod(n,10)
n=n/10
r=r+(a*(8**x))
END DO
PRINT *,”Decimal number=”,r
ENDPROGRAM octal_decimal

7.4)
! To convert to decimal to octal
PROGRAM decimal_octal
IMPLICIT NONE
INTEGER::x,n,r=0,a
PRINT *,”Enter decimal number”
READ *,n
PRINT *,”Decimal number=”,n
DO x=0,n-1
a=mod(n,8)
n=n/8
r=r+(a*(10**x))
END DO
PRINT *,”Octal number=”,r
ENDPROGRAM decimal_octal

7.5)
PROGRAM function
IMPLICIT NONE
REAL :: a,b,c,d,x
INTEGER :: i,n
REAL,allocatable,dimension(:) :: e,f
PRINT *,”Enter n”
READ *,n
allocate(e(n))
allocate(f(n))
PRINT *,”Enter a,b,c,d values”
READ *,a,b,c,d
PRINT *,”Enter x value”
DO i=1,n
READ *,e(i)
x = e(i)
IF (x<d) then
f(i) = ((a*((x)**2))+(b*x)+(c))
ELSEIF (x==d) then
f(i) = 0
ELSE
f(i) =(-(a*((x)**2))+(b*x)-(c))
ENDIF
END DO
DO i=1,n
PRINT *,i,e(i),f(i)
END DO
END PROGRAM function

7.6)
PROGRAM machine
IMPLICIT NONE
REAL :: s,c,p,e,a,t
INTEGER :: n
PRINT *,”Enter the cost of machine, salvage value and profit earned per annum”
READ *,c,s,e
PRINT *,”Enter percentage of profit through other alternatives”
READ *,p
a = (p*e)/100
t = ((c-s)/(e-a))
n = nint(t)
PRINT *,”The minimum number of years for which the machine should work so
that it is profitable is”,n
END PROGRAM machine

7.7)
PROGRAM tape_recorder
IMPLICIT NONE
REAL :: p,a,n,r,d,i
PRINT *,”Enter price of recorder”
READ *,p
PRINT *,”Enter down payment, amount paid per month and number of months
the amount was paid”
READ *,d,i,n
a = d+(i*n)
r =((((a/p)-1)*100)/n)
PRINT *,”The rate of interest per month=”,r
END PROGRAM tape_recorder

7.8)
PROGRAM equation
IMPLICIT NONE
REAL :: x(6)
INTEGER :: i
COMPLEX :: x(6), f(6)
PRINT *,”Enter the values of x,in parenthesis seperating real,imaginary parts by
comma”
DO i=1,6
READ *,x(i)
f(i) = 1+(x(i)**2/2)+(x(i)**4/24)-(50*sin(x(i))**2)+ (sqrt(4-x(i)**2))
ENDDO
10 FORMAT(7x,’Sl no’, 20x,’x’,25x,’f(x)’)
PRINT 10
DO i=1,6
PRINT *,i, x(i), f(i)
END DO
END PROGRAM equation

7.9)
PROGRAM sum_series
IMPLICIT NONE
REAL :: x,s=0
INTEGER :: n
PRINT *,”Enter the value of x”
READ *,x
DO n=1,10
s = s + (((-1)**n)*x**(n/2))/(n*(n+1))
END DO
PRINT *,”The sum of the series is”,s
END PROGRAM sum_series

7.10)
PROGRAM evaluate_function
IMPLICIT NONE
REAL :: f,a,b
INTEGER :: x=0,y=-10,n
DO n=1,7
a =((x**2)+(y**2)+(2*x*y))
b =((x**2)+(y**2)+(8*x*y))
f = a/b
PRINT *,x,y,f
x= x+2
y=y+2
END DO
END PROGRAM evaluate_function

7.11)
PROGRAM simple_compound
INTEGER :: d=1000.0,r=12,y=1,i,j,k
REAL :: s,c
DO i=1,5
DO y = 1,3
r=12
DO
if (r==18) exit
s= ((d*r*y)/100)
c = ((d*((1+r*0.01)**y ))-d)
print *,d,r,y,s,c
r=r+2
END DO
END DO
d = d+1000
END DO
END PROGRAM simple_compound
7.12)
PROGRAM evaluate_function
IMPLICIT NONE
REAL :: f,a,b,y,x
INTEGER :: n
DO
x=-6,3,1
f = (x**2)+(2*x)+(3)/(x-20)
PRINT *,x,f
END DO
DO x= -6.5,3.5,2
f = (x**2)+(2*x)+(3)/(x-20)
PRINT *,x,f
END DO
END PROGRAM evaluate_function

You might also like