Check Positive or Negative
Problem Description
Accept a number and determine if it is positive, negative, or zero.
Expected Output
Input: -5 -> Output: NUMBER IS NEGATIVE
Hints
Use IF-ELSE with comparison operators.
Solution
IDENTIFICATION DIVISION.
PROGRAM-ID. POSNEG.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NUM PIC S9(5).
PROCEDURE DIVISION.
DISPLAY "ENTER A NUMBER: ".
ACCEPT WS-NUM.
IF WS-NUM > 0
DISPLAY "NUMBER IS POSITIVE"
ELSE IF WS-NUM < 0
DISPLAY "NUMBER IS NEGATIVE"
ELSE
DISPLAY "NUMBER IS ZERO"
END-IF.
STOP RUN.
Explanation:
S in PIC allows signed numbers. Nested IF-ELSE handles multiple conditions.