Dremendo Tag Line

Check number is positive, negative or zero in C++

if else if - Question 2

In this question, we will see how to input a number and check if it is a positive number or a negative number or a zero in C++ programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.

Q2) Write a program in C++ to input a number and check if it is a positive number or a negative number or a zero.

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int n;
    cout<<"Enter a number ";
    cin>>n;
    if(n>0)
    {
        cout<<"Positive number";
    }
    else if(n<0)
    {
        cout<<"Negative number";
    }
    else
    {
        cout<<"Zero";
    }
    return 0;
}

Output

Enter a number -5
Negative number
video-poster