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, March 7, 2023

Qbasic program to reverse a number



Qbasic program to reverse a number


Qbasic program to reverse a number


Introduction:

QBasic is a high-level programming language developed by Microsoft for the DOS operating system. It was widely used in the late 1980s and early 1990s for educational and personal computing purposes. One of the common tasks that QBasic can perform is to reverse a number. Reversing a number means converting a number, such as 12345, into its reverse order, such as 54321. In this blog article, we will show you how to write a QBasic program to reverse a number.



Explanation of the code:


Step 1: Input a number.

The first step in creating a QBasic program to reverse a number is to input a number from the user. You can use the INPUT statement to prompt the user to enter a number.

Step 2: Reverse the number

Once you have the number, the next step is to reverse it. To do this, you need to extract each digit of the number and add it to a new variable in reverse order.

Step 3: Display the reversed number

The final step is to display the reversed number to the user. You can use the PRINT statement to do this.

CLS
INPUT "Enter any number: "; num
n = num
WHILE num <> 0
r = num MOD 10
rev = rev * 10 + r
num = num \ 10
WEND
PRINT n; "Reverse is: "; rev
END


Qbasic program to reverse a number by using SUB procedure.


DECLARE SUB rev ()
CLS
CALL rev
END


SUB rev
INPUT "Enter any number: "; num
WHILE num <> 0
r = num MOD 10
re = re * 10 + r
num = num \ 10
WEND
PRINT "Reverse number is: "; re
END SUB



Qbasic program to reverse a number by using FUNCTION procedure


DECLARE FUNCTION rev (num)
CLS
INPUT "Enter any number: "; num
PRINT "Reverse number is: "; rev(num)
END


FUNCTION rev (num)
WHILE num <> 0
r = num MOD 10
re = re * 10 + r
num = num \ 10
WEND
rev = re
END FUNCTION


Output:




Conclusion:


In conclusion, QBasic is a simple and easy-to-learn programming language that can be used to perform a variety of tasks, including reversing a number. By following the steps outlined in this article, you can create a QBasic program to reverse a number in just a few lines of code. We can also solve qbasic program to reverse a number by using SUB and FUNCTION procedure also. Whether you are a beginner or an experienced programmer, QBasic provides a great platform to learn and experiment with programming concepts.

You may also Read:





No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages