You are on page 1of 4

FORTRAN PAST QUESTIONS AND ANSWERS

2017/2018
1a. Define an expression
An expression is a combination of one or more operands, zero or more operators, and zero or
more pairs of parentheses
b. Mention types of operators and list the hierarchy of operators
Types of Operators
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Character
5. Bitwise operators
6. Assignment operators
Hierarchy of operators
1. Operators within parentheses
2. Exponential
3. Multiplication
4. Division
5. Addition
6. Subtraction
\1c. Using a do loop statement. Write a Fortran program to display the string
“COMPUTER SCIENCE” ten times

2a. Explain the following


i. Data type: This is a classification that specifies which type of value a variable has
and what type of operations can be applied to it without causing an error
ii. Constant: This refers to the fixed values that the program cannot alter during its
execution.
iii. Integer: This is any number without a decimal point between the prescribed limit
iv. Character: Character could be any symbol taken from the basic character set, i.e,
from the letters, the decimal digit, the underscore, and 21 special character
v. Variable: It is considered as a box that is capable of holding a single value of certain
type.
b. Write a program that reads five (5) integers and write their sum on the screen
program sum_of_5_numbers
implicit none
integer :: i,j,k,l,m,n
!
!program to sum 5 number
!
write (*,*)'enter any 5 numbers'
read (*,*)i,j,k,m,n
l=i+j+k+m+n
write (*,*)i,j,k,m,n,'='
print*,l
stop
end program sum_of_5_numbers

3a. List any five (5) intrinsic data type


1. Integer
2. Real
3. Complex
4. Logical
5. Character

b. What is an Identifier? State the rules for forming an identifier in OOFORTRAN


An Identifier is a name used to identify a variable, procedure, or any other user-defined item.
Rules for forming an identifier
It has no more than 31 characters
The first character must be a letter
The remaining characters may be letters, digits or underscore
Fortran identifiers are case insensitive.
c. Write an OOFortran program using array to find the average of ten(10) numbers

4a. Given the following declaration CHARACTER(LEN=30)::SNAME*10,


NAME*10,SEX*6,ADDRESS, CITY*5, PHONE_NO*11, how many character spaces are
given to each of the declared variable?
b. Considering the following declarations
CHARACTER(LEN=6)::Name1 = ‘John’,Name2=’Sammy’
CHARACTER(LEN=7)::Name3 = ‘Rita’,Name4=’Michael’
What is the result of the following concatenation?
(i) Name2//Name3
(ii) Name4//Name3
(iii) Name1//Name4
(iv) Name2//Name4

c. Given String A = ‘12345678’, Find


(i) A(:5)
(ii) A(3+x:), if x = 2
(iii) A(2:8)

5a. What is an array?


An array is a collection of similar types of data. Arrays can store a fixed-size sequential
collection of element of the same type.

b. Differentiate real constant from integer constant with examples


Integer constant: They represent whole number values e.g. 0, 1, -1, 300, 12345
Real constant: They represent fractional numbers e.g. 3.142, -14.08, 42.0,
c. Write an OOFortran program using the if…else statement to read in a student age,
hence the program must determine if the student is a teenager or an adult.

6ai. What do you understand by Control Structure?


Control structure is a block of programming that analyzes variables and chooses a direction in
which to go based on given parameters

aii. Explain the types of Control structure you know


1. Sequential Control Structure: It follows a serial or sequential flow in which the flow
depends on the series of instruction given to the computer
2. Selection Control Structure: This involves a number of conditions or parameters which
decides one out of several written modules
3. Iteration Control Structure: This employs a loop which involves a repeat statement
followed by a module known as the body of a loop.

b. Write a Fortran 90 program that will print the sum of even numbers between 1 to 100

7a. Evaluate the following arithmetic expression


(i) 100 = (1_200/100)**3
(ii) 2*4*5/3**2
(iii) 7*(8/2)**3+(8-2)**2-7*(8/2)**2

b. In the below program, find errors, if any, then write the correct program
Program bug
! this program is full of errors
Real : : a, b, c
a=b+c
read *, c
print *, a
end program simple
Solution
program bug
implicit none
real:: a, b, c
!
!this is full of errors
!
read(*,*)b,c
a=b+c
print*,a
stop
end program bug

You might also like