top of page
Writer's pictureThe Tech Platform

Write a C++ Program to check whether Given Number is Negative or Positive


Code:

#include <iostream>
using namespace std;

int main()
{
    cout << " ** Program to Check that given number is positive or negative** \n\n";

    int num;

    //taking user input
    cout << "Enter any non-zero Number to be checked:\n ";
    cin >> num;

    //when the condition inside the if() is true, then it enters the code block
    if (num > 0)
    {
        cout << "\nEntered number is positive";
    }
    else //when if is not executed then it moves to the else block
    {
        cout << "\nEntered number is negative";
    }

    cout << "\n\n\n";

    return 0;
}

Output:





The Tech Platform

0 comments

Comments


bottom of page