Finding whether a number is positive or negative with C++

Estimated read time 1 min read

In this example, we check whether the number entered from the keyboard is positive, negative or zero by using if-else if.

#include <iostream>
using namespace std;

int main() {
    int number;
    cout << "Please enter a number: ";
    cin >> number;

    if (number > 0) {
        cout << "Number is positive";
    } else if (number < 0) {
        cout << "Number is negative";
    } else {
        cout << "Number is zero";
    }

    return 0;
}
İbrahim Korucuoğlu

The author shares useful content he has compiled in the field of informatics and technology in this blog.

+ There are no comments

Add yours