Dremendo Tag Line

Check a number is positive or not in C++

if else - Question 2

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

Q2) Write a program in C++ to input a number and check if it is a positive number or not. A positive number is a number which is greater than 0.

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
    {
        cout<<"Not Positive Number";
    }
    return 0;
}

Output

Enter a number 5
Positive Number
video-poster