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

Yazar, bilişim ve teknoloji alanında derlediği faydalı içerikleri bu blogta paylaşmaktadır.