0% found this document useful (0 votes)
238 views

Fortran 77 Basics

1. The document contains the tasks for a CF LAB ASSIGNMENT 2. It includes 7 tasks which involve writing FORTRAN programs to calculate various mathematical functions and equations. 2. The tasks include programs to calculate expressions, compute area and circumference of circles, area of triangles, surface area and volume of rectangles and spheres, trigonometric functions, and equations for projectile motion. 3. For each task, the relevant equations and code for a FORTRAN program to calculate the results are provided.

Uploaded by

Ahmed Siddique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
238 views

Fortran 77 Basics

1. The document contains the tasks for a CF LAB ASSIGNMENT 2. It includes 7 tasks which involve writing FORTRAN programs to calculate various mathematical functions and equations. 2. The tasks include programs to calculate expressions, compute area and circumference of circles, area of triangles, surface area and volume of rectangles and spheres, trigonometric functions, and equations for projectile motion. 3. For each task, the relevant equations and code for a FORTRAN program to calculate the results are provided.

Uploaded by

Ahmed Siddique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

CF LAB ASSIGNMENT 2

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

Codes for the task:


Program FUNCTION LIBRARY
real y
PRINT*,''

! variable to store the values of given functions


! Space intentionally left

PRINT*,''
PRINT*,'------LAB 2 TASK 1--------'
PRINT*,''
PRINT*,''
print*,'

Question 1'

y=25.0 ** (1.0/ 2.0) * 3.5 ** (1.0 / 3.0)


print*,'25.0 ** 1 / 2 * 3.5 ** (1 / 3) =', y
PRINT*,''
PRINT*,''
print*,'

Question 2'

y=5.0 * (11.0 - 5.0) ** (2.0 / 4.0) + 9.0


print*,'5 * (11.0 - 5) ** 2 / 4 + 9 =', y
PRINT*,''
PRINT*,''
print*,'

Question 3'

y=2.0* 4.0 * 5.0 / 3.0 ** 2

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'

print*,'2.0 * 3.0 / ( 6.0*6.0 + 5.0*44.0) ** 0.25 =', y

end program FUNCTION LIBRARY

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]

Codes of the Task:


! Lab assignment 2 Task 2
Ahmed Siddique

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.

Codes for program:


! Lab 2 Assigment 2 (calculation of area of triangle)

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].

Codes for Program:


! Lab 2 Assigment 2
! Calculation of surface area and volume of a rectangle
real a,b,c,area,volume
! where
! a,b,c are the dimensions of rectangle in cm
print*,'-----LAB 2 TASK 4------'
print*,'Enter the dimensions (a,b,c) of rectangle in cm:'
print*,'a='
read*, a
print*,'b='
read*, b
print*,'c='
read*, c

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]

Codes for Program:


! Lab 2 Assigment 2
! Calculation of surface area and volume of a sphere
real r,area,volume,pi
! where
! r is the radius cm
print*,'-----LAB 2 TASK 5------'
print*,'Enter the radius of sphere in cm:'
Ahmed Siddique

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

Codes for Program:


Ahmed Siddique

MS-15-25710

program Trigonometric Functions


real a,b,c,x,y,f,rad
print*,'

' ! space for better look

print*,'

' ! space for better look

Print*,'-------LAB 2 TASK 6-------'


print*,'

'

print*,'

' ! space for better look

print*,'Enter the value of constants a, b, c and angle x(degree)'


print*,'a='
read*,

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*,'

' ! space for better look

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*,'

' ! space intentionally left for better look

print*,'(ax+b)/(ax-b) =' ,y
print*,'

' ! space for better look

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*,'

' ! space intentionally left for better look

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.

Codes for Program:


program Projectile Velocity And Height
c

Declartion of variables and program Title


real h,t,v,hi,a,vi
print*,'' ! space for better look
print*,'' ! space for better look
print*,'-------LAB 2 TASK 7-------'

Ahmed Siddique

MS-15-25710

print*,'' ! space for better look


print*,'' ! space for better look
c

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

You might also like