Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Tuesday, December 6, 2022

QBASIC program to display the input digit in reverse order

 QBASIC program to display the input digit in reverse order


CLS

INPUT "Enter any digit:"; d

n = d

WHILE d > 0

r = d MOD 10

s = s * 10 + r

d = INT(d / 10)

WEND

PRINT "Reverse digit of"; n; "is"; s

END

 

By using SUB procedure (SUB..END SUB)

DECLARE SUB rev (d)

CLS

INPUT "Enter any digit:"; d

CALL rev(d)

END

 

SUB rev (d)

n = d

WHILE d > 0

r = d MOD 10

s = s * 10 + r

d = INT(d / 10)

WEND

PRINT "Reverse of"; n; "is"; s

END SUB

 

By using FUNCTION procedure (FUNCTION…END FUNCTION)

DECLARE FUNCTION rev (d)

CLS

INPUT "Enter any digit:"; d

PRINT "Reverse digit of"; d; "is"; rev(d)

END

 

FUNCTION rev (d)

WHILE d <> 0

r = d MOD 10

s = s * 10 + r

d = d \ 10

WEND

rev = s

END FUNCTION


Output:



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages