- 2068 Chaitra · 8 marks
Greatest and smallest of ten numbers
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.
Write FORTRAN program to display greatest and smallest number from list ten elements.
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.
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.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Largest of n numbers in FORTRAN · Computer Programming, chapter 11
- Sort array ascending in FORTRAN · Computer Programming, chapter 11 · asked 2×
- Structure of a FORTRAN program · Computer Programming, chapter 11 · asked 5×
- Pass 2D array; largest and smallest · Computer Programming, chapter 7
- Quadratic equation roots in FORTRAN · Computer Programming, chapter 11 · asked 2×
- Add and subtract matrices in FORTRAN · Computer Programming, chapter 11
- 8086 ALP: largest and smallest, display · Microprocessor, chapter 3
- 8085 ALP: square of ten numbers · Microprocessor, chapter 2
- Prime number program: procedural and OOP · Object Oriented Programming, chapter 1
- C program: sum of two 8-bit BCD numbers · Embedded System, chapter 9