In the above C++ program to check whether the number is positive, negative or zero, We are using if condition since any number that is more than 0 will be positive and less than 0 will be negative.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # include <iostream> using namespace std; int main() { signed long num1 = 0 ; cout << "\n\n Check whether a number is positive, negative or zero :\n" ; cout << "-----------------------------------------------------------\n" ; cout << " Enter a number : " ; cin >> num1; if (num1 > 0 ) { cout << " The entered number is positive.\n\n" ; } else if (num1 < 0 ) { cout << " The entered number is negative.\n\n" ; } else { std::cout << " The number is zero.\n\n" ; } return 0 ; } |
Sample Output: Enter a number : 34 The entered number is positive.