C++ program to check whether a given number is positive, negative or 0

By | August 11, 2020

Write a C++ program to check whether a given number is positive, negative or 0.

Examples :

Number = -44
Output: Negative

Number = 0
Output: 0

Number = 50
Output: Positive

C++ implementation :

#include<bits/stdc++.h>
using namespace std;
void check(int num)

{   // if number is negative
    if(num<0)
        cout<<"Negative number"<<endl;
        
    // if number is positive
    else if(num>0)
        cout<<"Positive number"<<endl;
    
    // if number is niether negative nor positive, i.e., 0
    else if(num==0)
        cout<<"0"<<endl;
 
}

//Driver Program
int main()
{
   // take input
   int num;
   num = 50;
   check(num);
   return 0;
}

Output :

Positive number 

Note that number 0 is neither negative nor positive.



Please write comments if you find anything incorrect. A gentle request to share this topic on your social media profile.