run with cpp version
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter a number: ";
cin >> number;
if (number > 0) {
cout << "The number is positive." << endl;
} else if (number < 0) {
cout << "The number is negative." << endl;
} else {
cout << "The number is zero." << endl;
}
return 0;
}
This C++ program prompts the user to input a number. It then checks whether the entered number is positive, negative, or zero using conditional statements (if
, else if
, and else
). Depending on the value of the input number, the program outputs a corresponding message indicating whether the number is positive, negative, or zero.