ASCENDING AND DESCENDING OF 10 INPUT NUMBERS
How to arrange numbers in ascending order in Qbasic
Here in this post, we will write a program to sort a list of 10 numbers in ascending 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 ASCENDING ORDER"
FOR I = 1 TO 10
PRINT N(I)
NEXT I
END SUB
SORT NUMBER ASCENDING 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 ASCENDING 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