C++ Program to check whether a number is positive or negative
Program to Check whether a number is Positive or Negative
Here we will discuss how to check whether a number is positive or negative in C++ programming language.
- A number is positive if it is greater than 0
- N > 0, number is positive.
- To check this we use if else statement
- If the condition is true then the number is positive
- Otherwise the number is negative
- N< 0, number is negative.
Note: 0 is neither positive nor negative
- User gives an input
- Input is stored in an int type variable say prep
- prep is first checked for being 0.
- prep is then checked for being greater than 0.
- If prep is greater than 0 then the input is a positive number.
- Otherwise the number is a negative number.
// number is positive or negative
using namespace std;
cout<<"Enter a number: ";
//input is 0
cout<<"0 is neither positive nor negative";
//checking whether the number is positive or negative
cout<<check<<" is a positive number";
cout<<check<<" is a negative number";
Enter a number: 96
96 is a positive number