Professional Documents
Culture Documents
Subject:
Submitted By:
Ihtisham Ul Haq
Registration Number:
MS-22-AM-504821
Task 1.
a) Repeat all the examples of CF-1 Lab Assignment.
Example_1.
Programming Code:
program test01
print* , 'Hello world' ! A message
print* , '2+2=' ,2+2 !Addition operation
print* , '5/3=' ,5/3 !Division operation
print* , '5.0/3=' ,5.0/3
print* , 'sin (30)=' ,sin(30.0) !Trigonometric function sine
print* , "sin (30.0/180*3.14159268)=" ,sin (30.0/180*3.14159268)
end program test01
Output:
Hello world
2+2= 4
5/3= 1
5.0/3= 1.66666663
sin (30)= -0.988031626
sin (30.0/180*3.14159268) = 0.500000000
=========================End Example_1===========================
Example_2.
Programming Code:
program Arith
a = 2.500 !input
b = 7.030
!=========================== Calculations
c = a+b !Addition
d = a-b !Subtraction
e = a*b !Multiplication
f = a/b !Division
g = a**b !Exponentiation
!===========================Output
Print* , "Value_of_a =" ,a
Print* , "Value_of_b =" ,b
Print* , "Value_of_c =" ,c
Print* , "Value_of_d =" ,d
Print* , "Value_of_e =" ,e
Print* , "Value_of_f =" ,f
Print* , "Value_of_g =" ,g
end program Arith
Output:
Value_of_a = 2.50000000
Value_of_b = 7.03000021
Value_of_c = 9.53000069
Value_of_d = -4.53000021
Value_of_e = 17.5750008
Value_of_f = 0.355618775
Value_of_g = 627.362183
=========================End Example_2===========================
Example_3.
Programming Code:
program HYP_FUN
print*, "HYPERBOLIC FUNCTIONS"
print*, "sinh(x) function sinh(0.0) =" , SINH(0.0)
print*, "cosh(x) function cosh(0.0) =" , COSH(0.0)
print*, "tanh(x) function tanh(0.0) =" , TANH(0.0)
end program HYP_FUN
Output:
HYPERBOLIC FUNCTIONS
sinh(x) function sinh(0.0) = 0.00000000E+00
cosh(x) function cosh(0.0) = 1.00000000
tanh(x) function tanh(0.0) = 0.00000000E+00
=========================End Example_3===========================
Example_4.
Programming Code:
program OTHER_FUN
print*, "OTHER MATHEMATICAL FUNCTIONS"
print*, "sqrt(x) function SQRT(9.0) =" , SQRT(9.0)
print*, "abs(x) function ABS(-5.5) =" , ABS(-5.5)
print*, "exp(x) function EXP(0.0) =" , EXP(0.0)
print*, "alog(x) function ALOG(2.0) =" , ALOG(2.0)
print*, "alog10(x) function ALOG10(10.0) =" , ALOG10(10.0)
end program OTHER_FUN
Output:
OTHER MATHEMATICAL FUNCTIONS
sqrt(x) function SQRT(9.0) = 3.00000000
abs(x) function ABS(-5.5) = 5.50000000
exp(x) function EXP(0.0) = 1.00000000
alog(x) function ALOG(2.0) = 0.693147182
alog10(x) function ALOG10(10.0) = 1.00000000
=========================End Example_4===========================
Task 1.
b) Use the library functions in the table shown above in simple programs to get hold on
how they are used. You may refer to the document (file name: ‘ANSI FORTRAN77-
1978.pdf’) in the Fortran books folder for details. Test against at least five examples
and compare your results with the results of your calculator.
program Library_Fun_01
Output:
absolute value of given number
ABS(-19.8) = 19.7999992
ABS(16) = 16
ABS(4.6) = 4.59999990
ABS(-7) = 7
ABS(-111) = 111
Output:
DBLE(5)= 5.
DBLE(13.05)= 13.0500002
DBLE(4.1)= 4.0999999
DBLE(35.0)= 35.
DBLE(9)= 9.
Output:
DPROD(2.0,6.05)= 12.1000004
DPROD(4.2,8.0)= 33.5999985
DPROD(9.1,19.0)= 172.900007
DPROD(12.0,20.0)= 240.
DPROD(13.5,14.0)= 189.
Output:
Cosine values for numbers
cos(1.0) = 0.540302277
cos(2.0) = -0.416146845
cos(8.0) = -0.145500034
cos(15.0) = -0.759687901
cos(33.0) = -0.0132767474
Output:
LOG(1)= 0.
LOG(2)= 0.693147182
LOG(3)= 1.09861231
LOG(4)= 1.38629436
LOG(5)= 1.60943794
PROGRAM Library_Fun_06
print*, "INT(8.4)=" , INT(8.4)
print*, "INT(17.3)=" , INT(17.3)
print*, "INT(25.5)=" , INT(25.5)
print*, "INT(33.5)=" , INT(33.5)
print*, "INT(49.34)=", INT(49.34)
END PROGRAM Library_Fun_06
Output:
INT(8.4)= 8
INT(17.3)= 17
INT(25.5)= 25
INT(33.5)= 33
INT(49.34)= 49
Output:
Output:
MAX(7,7,45,88,99,76,56)= 99
MAX(6,9,34,88,96,34,89)= 96
MAX(12,76,9,5,4,85,99)= 99
MAX(55,76,45,87,34,87,79)= 87
MAX(99,88,67,67,55,74,23)= 99
Output:
Square roots of given numbers
SQRT(3.0)= 1.41421354
SQRT(4.0)= 2.
SQRT(46.0)= 6.78233004
SQRT(25.0)= 5.
SQRT(144.0)= 12.
Output:
MOD(90,20) = 10
MOD(220,30) = 10
MOD(10,10) = 0
MOD(22,35) = 22
MOD(325,345) = 325
Output:
NINT(7.8)= 8
NINT(9.9)= 10
NINT(6.2)= 6
NINT(4.3)= 4
NINT(5.5)= 6
Output:
REAL(10.4) = 10.3999996
REAL(20) = 20.
REAL(34) = 34.
REAL(40.05) = 40.0499992
REAL(50.60) = 50.5999985
Task 1.
c) Verify trigonometric and hyperbolic identities.
Programming Code:
program trigonometric_Fun
Output:
trigonometric function
sin(x) function sin(0.0) = 0.00000000
cos(x) function cos(0.0) = 1.00000000
tan(x) function tan(0.0) = 0.00000000
hyperbolic function
sinh(x) function sinh(0.0) = 0.00000000
cosh(x) function cosh(0.0) = 1.00000000
tanh(x) function tanh(0.0) = 0.00000000
=========================End Lab_Task_01===========================
Task 2.
Compute the results (Write Fortran Statements to evaluate the following expressions
and compare your calculations with calculators)
Programming Code:
program Lab_1_task_02
Output:
Results for the given mathematical expressions
1. Y = (25**(1/2)+3**(1/3)) = 7.21124744
2. Z = 5.0*(11.0-5.0**2)/4.0+9.0 = 54.0000000
3. F= 2*4*(5.0/2.0)**3 = 5.00000000
4. G = 100*(1+250.0/100.0)**3 = 4287.50000
5. X = (2.0*3.0)/(6.0*6.0+5.0*44.4)**(1.0/4.0) = 1.49708462
=========================End Lab_Task_02===========================
Task 3.
Write FORTRAN programs: (Define a, b, c and x in your programs and compute y in
these cases)
Programming Code:
program Lab_1_task_03
y=(a*x+b)/(a*x-b)
print*,'For b. Y = (a*x+b)/(a*x-b) Y=',y
y=2.5*log10(a)+cos(32*3.14/180.0)+abs(a**2.0-b**2.0)+ sqrt(2.0*a*b)
print*,'For c. Y = 2.5*log(a)+cos(32*3.14/180)+abs(a**2-b**2)+ sqrt(2*a*b) Y=',y
y=a*exp(-b*c)
print*,'For d. Y = a*exp(-a*b) Y=' ,y
Output:
=========================End Lab_Task_03===========================
Task 4.
Write a FORTRAN program to calculate the area of a triangle whose sides a, b and c
using Heron’s relationship.[𝐴𝑟𝑒𝑎 = √𝑠(𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐) ] , where
[s=(a+b+c)/2]. Also compute the angles opposite to the sides a, b and c, as A, B and C
respectively using the Law of cosines shown in figure. Discuss ten cases of different
values of a, b and c.
Programming Code:
program Lab_1_task_04
Output:
=========================End Lab_Task_04===========================