qbasic program Accept 10 numbers from user and print largest and smallest numbers
separately
Answers
Answered by
2
Answer:
This is the required QBASIC program for the question.
CLS
DIM ARR(9)
PRINT "ENTER 10 NUMBERS.."
FOR I = 0 TO 9
INPUT ">> "; ARR(I)
NEXT I
MAX = ARR(0)
MIN = ARR(0)
FOR I = 1 TO 9
IF ARR(I) > MAX THEN
MAX = ARR(I)
END IF
IF ARR(I) < MIN THEN
MIN = ARR(I)
END IF
NEXT I
PRINT "MAX: "; MAX
PRINT "MIN: "; MIN
END
How to Solve ?
- We will intialise an array which can store 10 values.
- Then, we will accept 10 numbers and store them in the array.
- Now, we will assume that the largest number is present at first index as well as the smallest number at first index.
- Now, we will loop through all the elements in the array.
- If any element is found greater than the highest number, then we will store that number in the max variable. Similarly, if an element is less than min, then we will store the result in min variable.
- At last, we will display the result.
Refer to the attachment.
•••♪
Attachments:
Similar questions
Accountancy,
1 month ago
Social Sciences,
1 month ago
Math,
3 months ago
Math,
3 months ago
English,
9 months ago
Math,
9 months ago