Contents
CSC 280 Answers to Practical Workbook – Introduction to Computer Programming, Modern FORTRAN Language Programs – CSC 280 is a course from Department of Computer Science, Faculty of Science in the University of Port Harcourt as well as other Universities. It is offered as borrowed course by other departments to enable them have the knowledge of programming. Though, it was introduced to the University as GES 101 – Computer Appreciation and Application.
In this course, ForTran – Formula Translator language is obeyed. Students are expected to run the programmes using Plato FORTRAN Application.
The objective of the course is that, students will learn how to run programmes on their own before semester ends. Thus, the initiation of the course in the University.
To pass this course is very easy as you are very lucky to come across this article. You must fill your manual or workbook very well. You can use download the PDF of the ones we have filled to fill yours. Also, you are required to do well in your Test then your exams.
FOR FORTRAN WORKBOOK ANSWERS PART I =
Operators | Actions |
() | Bracket (B) |
** | Exponentiation (E) |
/ | Division (D) |
* | Multiplication (M) |
+ | Addition (A) |
– | Subtraction (S) |
In FORTRAN order of precedence is BEDMAS
Operators | Actions |
< | Less than |
<= | Less than or equal to |
> | Greater than |
>= | Greater than or equal to |
= = | Equal to |
.or. | Logical OR |
.and. | Logical AND |
.not. | Logical NOT |
Operators | Actions |
() | Bracket (B) |
** | Exponentiation (E) |
/ | Division (D) |
* | Multiplication (M) |
+ | Addition (A) |
– | Subtraction (S) |
> | Greater than |
>= | Greater than or equal to |
< | Less than |
<= | Less than or equal to |
.not. | Logical NOT |
.and. | Logical AND |
.or. | Logical OR |
Lab 13: Simple Maths
Aim: To write a Fortran program to add, subtract, multiply or divide two numbers based on a selection.
ALGORITHM
If Selection equals 3, multiply A by B
If selection equals 4, divide A by B
OBSERVATIONS/OUTPUTS
Observation: the program performs simple arithmetic operation of addition, subtraction, multiplication and division on two real values that will be given as run time.
Output: if A=10, B=5 and selection =3. Then, the output will be:
A*B=50
Lab 14: LINEAR EQUATION
Aim: write fortran program to solve a pair of linear equation.
ALGORITHM
OBSERVATION AND OUTPUT
Observation: the program calculates the values of X and Y for any given pair of linear equations of the form:
A1X + B2Y = C1
A2X + B2Y = C2
Such that if A1*B2-A2B1=0 then, the equation has no solutions.
Output: if A1 =1, B1=1, C2=2
A2 = 1, B2 = -1, C2 = 2
The output will be:
X: 2.000000
Y: 0.000000
Lab 15: Sort integers in Ascending order
Aim: write a Fortran program to reads in three Integer numbers and displays them in ascending order.
ALGORITHM
If a is greater than c but less than b print b, a, c else print c, a, b
If b is greater than c and c is greater than a then print b, c, a else print c, b, a
Lab 16: CALCULATING INCOME TAX
Aim: to write a fortran program to calculate income tax of a person.
OBSERVATIONS/OUTPUT
Observation: the name of the program is income tax. ‘age’ is declare as INTEGER while ‘tax’ and ‘income’ are declare as REAL. The program takes the age and yearly income of the subject using READ statement compares the age and yearly income of the subject with a specified range of values for age and yearly income, and determines whether subject will pay income or not. If the subject will pay income tax, the program will determine how much income tax should be paid.
Output: Let age = 85, income = 450000
The output will be:
NO INCOME TAX TO BE PAID
Lab 17: Test grading
Aim: Enter the following program code into a Fortran compiler and print the result with different test scores and exam score to determine the grade assigned to the computation of the score. Explain the reason while test total is assigned the value of 1 in the program.
ALGORITHM
OBSERVATION/OUTPUT
Observation: the program calculates the total score of a student in a particular course. Three test scores are supplied (test 1, test 2, and test 3), their average is calculated and added to the exam score of the student this is the total score of the student (i.e. testtotal) in a particular course.
Output: Let test 1=6, test 2=7, test 3=9 and exam =5
The output will be:
Average of the three test score is 22
Exam score is 56
Total score is percentage is 78
Write a FORTRAN program to calculate the roots of a quadratic equation using the general formula. The program should be able to check if the result will be real roots or not
Source code:
! Program to calculate the root of a quadratic equation
Program Equation
Implicit None
Real:: a, b, c, d, root1, root2
Write (*,*) “Enter the value of a, b and c”
Read (*,*) a, b, c
d = b**2 – 4*a*c ! calculating discriminant
if (d≥0) then d = SQRT (d)
root1 = (-b + d)/2*a
root2 = (-b – d)/2*a
Write (*,*) “The roots are:” root1, “and”, root2
else
Write (*,*) “The roots are complex and cannot be calculated”
end if
End program Equation
Write a FORTRAN program that reads an item
Lab 18: Factorial
Aim: A fortran program that calculate the factorial of any given number
ALGORITHM
multiply nfact by n,
print n and nfact,
end do
OBSERVATIONS/OUTPUT
Observation: the name of the program is factorial and it calculates the factorial of any value supplied to k. it also checks if n is less than 20 am prints the value of nfact.
Output: if k=3
6
Lab 19: Static Array
Aim: A program that demonstrate the use of static array
ALGORITHM
Add arrays v and k, and store in
Print value of z (i) for each value of i
End do
OBSERVATIONS /OUTPUT
Observations: the program contains two one dimensional arrays (i.e. v and k) with values and another one dimensional array without initializing it. The values arrays v and k are added and stored in array z
Output: 16
32
14
28
Lab 20: Sum of Consecutive numbers
Aim: A program that computes the sum of any “k” consecutive numbers.
ALGORITHM
Sum all values from 1to k
end do
OBSERVATIONS/OUTPUT
Observation: the program is testsum. This program sums from 1 to a given value of k and display the result.
Output: if k = 5
The sum is: 15
Lab 21: DO – Loop
Aim: A FORTRAN program that demonstrate the of a DO – Loop
ALGORITHM
Increase the value of j by 1
Multiply j by 9 and store the rest
Display the value of j and k
end do loop.
OBSERVATIONS/OUTPUT
Observation: the name of the loop demo. The do loop has initial value of 8, final value of and an increment of -1. The program prints the value of j and k at each iteration.
Output:
Lab 22: Nested Do Loop
Aim: A program that demonstration the of a nested do loop.
ALGORITHM
Do j = 1, 2
Print the product of i and j
end do
OBSERVATIONS/OUTPUT
Observation: the name of the program is testloop ad it illustrates the use of nested do loop. If prints the product of i and j
Output:
i*j = 1
i*j = 2
i*j = 2
i*j = 4
i*j = 3
i*j = 6
Lab 23: Addition of Matrix
Aim: A Fortran program that can ADD the elements of a two (3×4) matrix array.
ALGORITHM
OBSERVATIONS/OUTPUT
Observation: The program contain three two-dimensional array namely: v, k and z. Values will be supplied to array v and k, and the values will be added and stored in third array named z. i.e. z(i, j) = v(i, j) + k(i, j). The arrays declared in the program are 2×3 two dimensional arrays and a nested do looped is used to supply values to array v and k, and to perform the addition operation.
Output: the addition of the two arrays
Position 11 is 4
Position 12 is 7
Position 13 is 0
Position 21 is 8
Position 22 is 6
Position 23 is 10
Lab 24: Sum and Average of N Consecutive
Algorithm
Supply value to data item
Sum all data item values
end do
Observations/Output
Observation: The program calculates the sum of the values stored in dataitem and calculates the average
Output:
If count = 3
When count = 1
dataitem = 4
when count = 2
dataitem = 5
when count = 3
dataitem = 6
average = 5.00000
To be updated on all Uniport Materials for Examination and Sure Questions
Subscribe to this site using your Email address for FREE
LIKE our Facebook page for updates
FOLLOW our Twitter Handle for udpates
NYSC Batch C Stream 2 2024 Update | Online Registration Starting Date, Mobilization and Camp…
Nigerian Army (NA) 88RRI Recruitment 2024/2025 Application Form Portal - Do you want to apply…
Chief Security Officer (CSO) at United Nigeria Airlines: How to Apply: United Nigeria Airlines is…
Safety and Quality Manager at United Nigeria Airlines - Apply Here: I am directed to…
NYSC Corps Members Allowance - DG Gives Assurance of Stipend Hike This article is directed…
How To Check If Your FG Loan Application Status Is Verified: As the Federal Government…