WRITE A QBASIC PROGRAM TO SORT NUMBER IN DESCENDING ORDER

 

DESCENDING OF 10 INPUT NUMBERS

How to arrange numbers in descending order in Qbasic

Here in this post, we will write a program to sort a list of 10 numbers in descending order.


Solution



CLS
DIM N(10)
FOR I = 1 TO 10
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
FOR I = 1 TO 10
FOR J = 1 TO 10 - I
IF N(J) < N(J + 1) THEN SWAP N(J), N(J + 1)
NEXT J
NEXT I
PRINT "NUMBERS ARRANGED IN DESCENDING ORDER"
FOR I = 1 TO 10
PRINT N(I)
NEXT I

END SUB

SORT NUMBER IN DESCENDING ORDER USING SUB PROCEDURE


DECLARE SUB SORT (N())
CLS
DIM N(10)
FOR I = 1 TO 10
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
CALL SORT(N())
PRINT "NUMBERS ARRANGED IN DESCENDING ORDER"
FOR I = 1 TO 10
PRINT N(I)
NEXT I
END


SUB SORT (N())
FOR I = 1 TO 10
FOR J = 1 TO 10 - I
IF N(J) < N(J + 1) THEN SWAP N(J), N(J + 1)
NEXT J
NEXT I

END SUB