ASCENDING AND DESCENDING OF 10 INPUT NUMBERS



152. WAP to enter any 10 numbers and sort in ascending order.

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

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
153.   WAP to enter any 10 numbers and sort in descending order.
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

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

Comments

Popular posts from this blog

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS

PALINDROME AND ARMSTRONG PROGRAMS