#include <iostream>
using namespace std;
int main(){
int num;
cout<<"Enter the number to check: ";
cin>>num;
if(num>0){
cout<<"Number "<<num<<" is positive!"<<endl;
}else if(num<0){
cout<<"Number "<<num<<" is negative!"<<endl;
}else{
cout<<"Number is zero!"<<endl;
}
return 0;
}
Output:The working of the program is as follows:
2. The program starts by including the necessary header files for input/output operations.3. The main function starts by declaring an integer variable
num
.4. It then prompts the user to enter a number using
cout
and cin
statements.5. The user input is stored in the
num
variable.6. The program checks if the value of
num
is greater than 0 using an if
statement.7. If
num
is greater than 0, it prints a message to the console saying that the number is positive using cout
statement.8. If
num
is less than 0, the program checks the next condition using an else if
statement.9. If
num
is less than 0, it prints a message to the console saying that the number is negative using cout
statement.10. If both conditions fail, the program prints a message to the console saying that the number is 0 using
cout
statement.11. Finally, the main function returns 0, indicating successful execution of the program.
No comments:
Post a Comment