Tuesday, October 25, 2011

Qbasic (Input name of 10 names and sort in ascending order)

DECLARE FUNCTION SOR$(N$())
CLS
DIM N$(10)
PRINT "ENTER NAME OF TEN STUDENTS"
FOR I = 1 TO 10
INPUT N$(I)
NEXT
X$=SOR$(N$())
END

FUNCTION SOR$(N$())
FOR I = 1 TO 10
FOR J = 1 TO 10
IF N$(I) < N$(J) THEN SWAP N$(I) , N$(J)
NEXT
NEXT
FOR I = 1 TO 10
PRINT N$(I)
NEXT
END FUNCTION

No comments:

Post a Comment