---
title: "Largest of n numbers in FORTRAN"
subject: "Computer Programming"
chapter: 11
key: "semester_1/computer_programming:fortran-largest-n-numbers"
source: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-largest-n-numbers
site: BCT Engineering
---

# Largest of n numbers in FORTRAN

Computer Programming · Chapter 11: Programming Language: FORTRAN

- Asked in: 2073 Shrawan, 5 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-largest-n-numbers
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-11

## Question

Write a FORTRAN program to read n numbers and display largest number among them.

## 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.

## Answer

**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.

```fortran
      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).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Why is BIG set to the first number entered?
   A. Because it is the largest of all
   B. So later numbers can be compared against a real data value
   C. Because the loop runs 1 to n
   D. To avoid using an IF
   Answer: B. BIG starts with an actual value from the data so the comparison is valid even if all numbers are negative. (Key point: Initial largest)

2. Why does the loop run from I = 2 to N?
   A. The first number is already read into BIG
   B. FORTRAN loops start at 2
   C. The last number is skipped
   D. N is counted from 0
   Answer: A. The first number is taken as BIG, so only the remaining n - 1 numbers need reading and comparing. (Key point: Loop range)

3. When is BIG replaced?
   A. When X .LT. BIG
   B. When X .GT. BIG
   C. On every pass
   D. Never
   Answer: B. BIG is replaced whenever the new number is larger, so it ends with the maximum. (Key point: Updating the maximum)

## Related in Computer Programming

- [Structure of a FORTRAN program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-structure) — Computer Programming, chapter 11, asked 5×
- [Sort array ascending in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-sort-ascending) — Computer Programming, chapter 11, asked 2×
- [Function returning largest of array](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Alargest-from-array-function) — Computer Programming, chapter 7
- [Sum of two matrices in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-matrix-sum) — Computer Programming, chapter 11
- [Transpose m×n matrix in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-matrix-transpose) — Computer Programming, chapter 11
- [Read records until end; show nth record](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-worker-nth-record) — Computer Programming, chapter 10, asked 2×

## Related in other subjects

- [8086 ALP: largest and smallest, display](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-largest-smallest-display) — Microprocessor, chapter 3
- [Prime number program: procedural and OOP](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprime-procedural-oop) — Object Oriented Programming, chapter 1
- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [8086 ALP: count vowels and display string](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-count-vowels-display) — Microprocessor, chapter 3
