Professional Documents
Culture Documents
Note: in above figure 11.1 , at the bottom of the coding sheet, the row
number and column number of cursor position is displayed as 3:8 (3 rd
row and 8th column) for STOP statement.
5. /(slash) format:
This is format is used to change the line which is exactly as \n
used for same purpose in C programming.
It can be used either just after the number format or placing
the comma as
1. FORMAT(I2/,I4) which prints I2 in one line and line
changes so, I4 is printed in next line.
2. FORMAT(I2,/,I4) which has same effect as above i.e. prints
I2 in one line and line changes and I4 is printed in next
line.
If you put double slash i.e. // then its effect will exactly
like \n\n in C programming which changes two lines. In
the same way, we can put triple slash(///) to change 3
lines and so on.
Here, due to T10 , the value following T10 only starts from
10th column and more two blanks are left than previous
output.
8. Quote format
To print any message, quote format is used. Anything kept
within single quotes is printed as it is.
For example, if we want print, Hello world then we can write
Quote format as
FORMAT (Hello world)
This is very useful format for giving the clear meaning while
displaying any result.
For example, if we have AREA value to printed then we can
write Format statement for this as
FORMAT (The area of given rectangle is, F10.2,sq.cm.)
In the output, it will be like
The area of given rectangle is 1234567.24
Hardware number: A computer may be having more than one input devices e.g.
card reader, magnetic tape, key board etc. For selecting particular hardware
device, a unique hardware number is used like 1 for card number, 2 for
magnetic tape and 3 for the keyboard and monitor (VDU). In personal
computers, usually the keyboard is the only input device. So we put the
asterisk symbol (*) in the place of hardware number.
Examples:
i) Read a integer number of 3 digits from keyboard.
ii) Read two real numbers of total width 10 and decimal
width 3.
OUTPUT
OUTPUT 1:
OUTPUT 2:
2. Logical IF statement
The logical if condition checks any given logical condition and
transfers the control accordingly.
The general format of the statement is
If(condition) statement
Where the condition is a logical condition, statement is an
executable statement. if the condition is true the statement is
executed and then goes to the next statement. if the
condition is false the control goes to the next statement.
Logical condition:
Relational operator Symbol used in FORTRAN
Less than(<) .LT.
Less than equal to(<=) .LE.
Greater than(>) .GT.
Greater than equal to(>=) .GE.
Equal to (=) .EQ.
Not equal to(!=) .NE.
Examples:
Suppose we want to read 100 numbers and print all the numbers less
than 45. The following is the Do Loop needed.
DO 10 l=1,100
DO 1 I=1,N
PRINT *,'ENTER THE ARRAY ELELMENT ',I
READ(*,20)A(I)
20 FORMAT(F5.2)
1 CONTINUE
B=A(1)
DO 5 I=2,N
IF(B.LT.A(I)) B=A(I)
5 CONTINUE
WRITE(*,30)B
30 FORMAT('THE LARGEST ELEMENT OF GIVEN ARRAY IS: ',F5.2)
STOP
END
OUTPUT
DO 20 I=1, 50
DO 20 J=1, 50
20 READ(*,2) A(I,J)
2 FORMAT(F10.3)
But we can use the implied DO loop and write this as a single
statement as follows:
READ(*,2)((A(I,J),J=1,20),I=1,50)
It is noticed that the outer loop has I as running variable and
inner loop has J.
Examples:
The following two lines read and print a matrix of order MXN
READ(*,1)((A(I,J),J=1,N),I=1,M)
WRITE*,2)((A(I,J),J=1,N),I=1,M)
The typical example of a two dimensional array is matrix. Consider a
matrix
A= 1 2 3
4 5 6
7 8 9
This matrix has 3 rows and 4 columns. This is called as 34 matrix.
This can be represented by a subscripted variable with two subscripts.
2. MATRIX MULTIPLICATION
C A PROGRAM TO FIND THE PRODUCT OF TWO MATRICES
DIMENSION A(25,25),B(25,25),C(25,25)
WRITE(*,*) 'ENTER THE ORDER OF MATRIX A '
READ(*,2)M1,N1
2 FORMAT(2I5)
WRITE(*,*) 'ENTER THE ORDER OF MATRIX B '