- 2073 Shrawan · 5 marks
Largest of n numbers in FORTRAN
Short answer
Read n and first number as initial largest. Then read remaining n-1 numbers; if a number exceeds current largest, update largest. Output largest. Example: n=5, numbers 12, 45, 7, 89, 23 gives largest 89.
Write a FORTRAN program to read n numbers and display largest number among them.
Method. Read n and the first number, and take it as the largest, BIG. Read each of the remaining n − 1 numbers and replace BIG whenever the new number is larger. No array is needed.
PROGRAM LARGE
INTEGER N, I
REAL X, BIG
PRINT *, 'HOW MANY NUMBERS?'
READ *, N
PRINT *, 'ENTER THE NUMBERS'
READ *, BIG
DO 10 I = 2, N
READ *, X
IF (X .GT. BIG) BIG = X
10 CONTINUE
PRINT *, 'THE LARGEST NUMBER IS ', BIG
STOP
END
Sample: n = 5 and the numbers 12, 45, 7, 89, 23 give THE LARGEST NUMBER IS 89.0 (the number of decimal places shown by list-directed output depends on the compiler).
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Structure of a FORTRAN program · Computer Programming, chapter 11 · asked 5×
- Sort array ascending in FORTRAN · Computer Programming, chapter 11 · asked 2×
- Function returning largest of array · Computer Programming, chapter 7
- Sum of two matrices in FORTRAN · Computer Programming, chapter 11
- Transpose m×n matrix in FORTRAN · Computer Programming, chapter 11
- Read records until end; show nth record · Computer Programming, chapter 10 · asked 2×
- 8086 ALP: largest and smallest, display · Microprocessor, chapter 3
- Prime number program: procedural and OOP · Object Oriented Programming, chapter 1
- C program: sum of two 8-bit BCD numbers · Embedded System, chapter 9
- 8086 ALP: count vowels and display string · Microprocessor, chapter 3