Fortran 77 Basics
Fortran 77 Basics
TASK 1:
Compute the results (Write FORTRAN program and also compute via hand
calculations)
1. 25.0 ** 1 / 2 * 3.5 ** (1 / 3)
2. 5 * (11.0 - 5) ** 2 / 4 + 9
3. 2 * 4 * 5 / 3 ** 2
4. 100 + (1 + 250 / 100) ** 3
5. + 2.0 * 3.0 / ( 6.0*6.0 + 5.0*44.0) ** 0.25
PRINT*,''
PRINT*,'------LAB 2 TASK 1--------'
PRINT*,''
PRINT*,''
print*,'
Question 1'
Question 2'
Question 3'
Ahmed Siddique
MS-15-25710
print*,'2 * 4 * 5 / 3 ** 2 =', y
y=100.0 + (1.0 + 250.0 / 100.0) ** 3.0
print*,'
Question 4'
PRINT*,''
PRINT*,''
print*,'100 + (1 + 250 / 100) ** 3 =', y
PRINT*,''
PRINT*,''
y=2.0 * 3.0 / ( 6.0*6.0 + 5.0*44.0) ** 0.25
print*,'
Question 5'
Output of Program:
Task 2:
Write a FORTRAN program to calculate the circumference and area of a circle of
given radius r. Take radius input from the user. [Circumference=2r, Area=r2]
MS-15-25710
real r,a,c
!where r,a &c represent radius,area and circumference respectively
print*,'------LAB ASSIGNMENT 2 TASK 2-------'
print*,'Calculation of circumference and radius of circle'
Print*,'Enter the value of radius:'
read*,
pi=3.1428
a=pi*(r**2)
c=2*pi*r
print*,'The area of the circle is',a
print*,'The circumference of the circle is',c
end
Output of Program:
Task 3:
Write a FORTRAN program to calculate the area of a triangle whose sides a, b and c
are taken as input from user.
Ahmed Siddique
MS-15-25710
real a,b,c,s,area,x,y,z
! where
! a,b,c are the lengths of sides of triangle in cm
! x,y and z are variables to make calculations easier
print*,'-----LAB 2 TASK 3------'
print*,'Enter the length of sides(a,b,c) of triangle in cm:'
print*,'a='
read*, a
print*,'b='
read*, b
print*,'c='
read*, c
s=(a+b+b)/2
x=s-a
y=s-b
z=s-c
area=sqrt(s*x*y*z)
print*,'area of the triangle with sides', a, b,'&', c, 'is', area
end
Output of Program:
Ahmed Siddique
MS-15-25710
Task 4:
Write a FORTRAN program to calculate the surface area and volume of a rectangular
box with dimensions a, b and c. Take the dimensions input from the user. [Surface
Area=2(ab+bc+ca), volume=abc].
Ahmed Siddique
MS-15-25710
volume=a*b*c
area=2*((a*b)+(b*c)+(c*a))
print*,'surface area of the rectangle is', area
print*,'volume of the rectangle is', volume
end
Output of Program:
Task 5:
Write a FORTRAN program to calculate surface area and volume of a sphere of
radius r
(input from the user). [Surface Area=4r2, Volume= 4r3/3]
MS-15-25710
print*,'r='
read*, r
pi=3.14159
volume=(4*pi*(r**3))/3
area=(4*pi*(r**2))
print*,'surface area of the sphere is', area
print*,'volume of the sphere is', volume
end
Output of Program:
Task 6:
Write FORTRAN programs: (Take a, b, c and x from user and compute y in these
cases)
a. y=aCosx+bCos2x+cCos3x
b. y=(x+b)/(ax-b)
c. y=2.5log10a + Cos 32o + |a2-b2|+2
d. y=ae-bc
MS-15-25710
print*,'
'
print*,'
print*,'b='
read*, b
print*,'c='
read*, c
print*,'x='
read*, x
rad=(x*3.14159/180) ! coversion of degree measures into radian.
print*,'For given values of constants and angle the results are:'
print*,'
y=(a*Cos(rad))+(b*Cos(2*rad))+(c*Cos(3*rad))
print*,'aCosx+bCos2x+cCos3x =', y
y=((a*x)+b)/((a*x)-b)
print*,'
print*,'(ax+b)/(ax-b) =' ,y
print*,'
y=(2.5*(log10(a)))+(Cos(32.0*180/3.14159))+(abs((a**2.0)-(b**2.0)))
+sqrt(2.0)
print*,'2.5log10a + Cos 32 + |a2-b2| + sqrt(2) =', y
print*,'
y=a*(exp(-b*c))
Ahmed Siddique
MS-15-25710
print*,'a.exp(-bc) =', y
end program Trigonometric Functions
Output of Program:
Task 7:
If a projectile is launched from an initial height of h=hi with an initial vertical
velocity
of v=vi and a vertical acceleration of a, then the equations of projectile height and
velocity are:
height = 0.5 * a * time ** 2 + vi * time + hi
velocity = a * time + vi
Take a, time, hi, vi input from the user and print the value of velocity and height.
Ahmed Siddique
MS-15-25710
Input
print*,'provide the value of of following parameters in SI units'
print*,'' ! space for better look
print*,'initial velocity :'
read*,vi
print*,'initial height :'
read*,hi
print*,'accelration A of projectile :'
read*,a
print*,'time taken by projectile :'
read*,t
Execution
h =(0.5 * a *( t ** 2.0 ))+ (vi * t) + hi
v =(a * t) + vi
Results
print*,'' ! space for better look
print*,'' ! space for better look
print*,'height of projectile after ',int(t),' seconds = ',h,'m'
print*,'' ! space for better look
print*,'' ! space for better look
print*,'velocity of projectile after ',int(t),' seconds = ',v,'m/s'
end program Projectile Velocity And Height
Output of Program:
Ahmed Siddique
MS-15-25710
Ahmed Siddique
MS-15-25710