Table of Contents
Overview
Below is the program to check whether a user input number is positive, negative, or zero.
REM Program to check if a number is positive, negative or zero
INPUT "Enter a number: "; n
IF n > 0 THEN
PRINT n;" is positive number"
ELSE IF n < 0 THEN
PRINT n;" is negative number"
ELSE
PRINT n;" is zero"
END IF
END
Output
Explanation
Let’s first understand positive, negative, and zero numbers. Positive numbers are the ones that are greater than 0 while negative numbers are the ones that are lower than 0 and obviously 0 is a zero. So, we will check if the number is greater than 0 using greater than symbol (>) then the number is positive. Also, we will check if the number is lower than 0 using a lower than symbol (<).
Note these symbols >, < are known as comparison operators.
More Programs
https://thinkshare.one/learn/programming/qbasic/