---
title: "Greatest and smallest of ten numbers"
subject: "Computer Programming"
chapter: 11
key: "semester_1/computer_programming:fortran-greatest-smallest-ten"
source: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-greatest-smallest-ten
site: BCT Engineering
---

# Greatest and smallest of ten numbers

Computer Programming · Chapter 11: Programming Language: FORTRAN

- Asked in: 2068 Chaitra, 8 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-greatest-smallest-ten
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-11

## Question

Write FORTRAN program to display greatest and smallest number from list ten elements.

## Short answer

Read ten numbers into array. Set big and small to first element. Loop from 2 to 10: update big if element is larger, small if smaller. Print greatest and smallest. Example: input 4 9 -2 15 7 3 22 -8 6 11 gives greatest 22.0, smallest -8.0.

## Answer

**Method.** The ten numbers are read into an array `X`. `BIG` and `SMALL` both start with `X(1)`. A loop from 2 to 10 compares each element: it updates `BIG` if the element is larger and `SMALL` if it is smaller.

```fortran
      PROGRAM MAXMIN
      REAL X(10), BIG, SMALL
      INTEGER I
      PRINT *, 'ENTER TEN NUMBERS'
      READ *, (X(I), I = 1, 10)
      BIG = X(1)
      SMALL = X(1)
      DO 10 I = 2, 10
         IF (X(I) .GT. BIG) BIG = X(I)
         IF (X(I) .LT. SMALL) SMALL = X(I)
   10 CONTINUE
      PRINT *, 'GREATEST NUMBER = ', BIG
      PRINT *, 'SMALLEST NUMBER = ', SMALL
      STOP
      END
```

**Sample:** the numbers 4 9 -2 15 7 3 22 -8 6 11 give greatest 22.0 and smallest -8.0.

## Check yourself

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

1. Why are BIG and SMALL both set to X(1) at the start?
   A. They are compared with real data, so the first element is both the largest and smallest so far
   B. Because X(1) is always the smallest
   C. To skip the loop
   D. Because arrays start at 0
   Answer: A. With only one element examined, it is both the greatest and smallest so far; later elements update them. (Key point: Initial values)

2. What does the loop DO 10 I = 2, 10 do?
   A. Reads the numbers
   B. Compares elements 2 to 10 with BIG and SMALL
   C. Sorts the array
   D. Reverses the array
   Answer: B. X(1) is already used for the start, so elements 2 to 10 are compared. (Key point: Loop range)

3. Why are two separate IF statements used in the loop?
   A. An element may update BIG, SMALL or neither, and each test is independent
   B. Only one can be true
   C. To print twice
   D. Because the array is real
   Answer: A. One test checks for a new greater value and the other for a new smaller value; each is independent. (Key point: Two separate IFs)

4. For the numbers 4 9 -2 15 7 3 22 -8 6 11, what are the greatest and smallest?
   A. 15 and -2
   B. 22 and -8
   C. 11 and 4
   D. 22 and -2
   Answer: B. The largest value in the list is 22 and the smallest is -8. (Key point: Sample result)

## Related in Computer Programming

- [Largest of n numbers in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-largest-n-numbers) — Computer Programming, chapter 11
- [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×
- [Structure of a FORTRAN program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-structure) — Computer Programming, chapter 11, asked 5×
- [Pass 2D array; largest and smallest](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-2d-array-largest-smallest) — Computer Programming, chapter 7
- [Quadratic equation roots in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-quadratic-roots) — Computer Programming, chapter 11, asked 2×
- [Add and subtract matrices in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-matrix-add-subtract) — Computer Programming, chapter 11

## 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
- [8085 ALP: square of ten numbers](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-square-numbers) — Microprocessor, chapter 2
- [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
