Challenge: Positive, Negative or Zero
Completed
Read one whole number and print positive, negative or zero.
Input
One integer.
Output
One word.
Example
Input
5
Output
positive
Editor
C++
Hints
Use if, else if and else.
Zero is neither > 0 nor < 0.
Solution explanation
Three paths, and exactly one of them runs.
Show solution
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n > 0) {
cout << "positive\n";
} else if (n < 0) {
cout << "negative\n";
} else {
cout << "zero\n";
}
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module