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

Wednesday, November 30, 2022

Writing a QBASIC Program to Check Input Number is Odd or Even

QBASIC program to check input number is odd or even

 




Introduction: 

QBASIC is a high-level programming language that is widely used for creating small-scale applications. It is easy to learn, efficient, and effective in developing simple yet powerful programs. One such program is checking whether an input number is odd or even. In this article, we will guide you through creating a Program to Check Input Number is Odd or Even. We will provide step-by-step instructions, sample code, and FAQs to help you get started.

What is odd and even number in QBASIC?


In QBASIC, an even number is a whole number that can be divided by 2 without leaving a remainder, while an odd number is a whole number that cannot be divided by 2 without leaving a remainder. For example, 2, 4, 6, 8, and 10 are even numbers, while 1, 3, 5, 7, and 9 are odd numbers. To determine whether a number is odd or even in QBASIC, we use the "MOD" operator to calculate the remainder when the number is divided by 2. If the remainder is 0, then the number is even. Otherwise, the number is odd.

Step-by-Step Guide to Creating a QBASIC Program to Check Input Number is Odd or Even

  1. To create a QBASIC program to check whether an input number is odd or even, follow these steps:
  2. Start QBASIC and create a new program.
  3. Prompt the user to enter a number.
  4. Read the input number from the user and store it in the variable.
  5. Use an "if" statement to check if the number is odd or even.
  6. If the number is even, display a message saying "The number is even."
  7. If the number is odd, display a message saying "The number is odd."
  8. End the program.

Sample Code for QBASIC Program to Check Input Number is Odd or Even


Here is the sample code for the QBASIC program to check whether an input number is odd or even:


CLS
INPUT "Enter any number"; no
IF no MOD 2 = 0 THEN
PRINT no; "is even number"
ELSE
PRINT no; "is an odd number"
END IF
END


We can solve above program by using SUB and FUNCTION procedures also.


By using SUB procedure (SUB..END SUB)
DECLARE SUB num (no)
CLS
INPUT "Ente any number"; no
CALL num(no)
END

SUB num (no)
IF no MOD 2 = 0 THEN
PRINT no; "is even number"
ELSE
PRINT no; "is odd number"
END IF
END SUB

By using FUNCTION procedure (FUNCTION …END FUNCTION)
DECLARE FUNCTION num$ (no)
CLS
INPUT "Enter any number"; no
p$ = num$(no)
PRINT no; p$
END

FUNCTION num$ (no)
IF no MOD 2 = 0 THEN
s$ = "is even number"
ELSE
s$ = "is odd number"
END IF
num$ = s$
END FUNCTION


Output



FAQs


Q: What is QBASIC?
A: QBASIC is a high-level programming language used for creating small-scale applications.

Q: How do I create a QBASIC program to check whether a number is odd or even?
A: Follow the steps provided in this article to create a QBASIC program that checks whether an input number is odd or even.

Q: What is the "if" statement used for in QBASIC? 
A: The "if" statement is used for conditional execution of code based on whether a condition is true or false.

Q: What does the "MOD" operator do in QBASIC? 
A: The "MOD" operator is used to calculate the remainder when one number is divided by another.

Conclusion


Creating a QBASIC program to check whether an input number is odd or even is a straightforward process. By following the steps provided in this article, you can create a program that effectively checks whether an input number is odd or even. QBASIC is a great language for beginners, and this program is an excellent way to get started with programming. We hope this article has been helpful in guiding you through the process of creating a QBASIC program to check whether an input number is odd or even.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages