Challenge: Positive, Negative or Zero
Completed
Read a whole number and print positive, negative or zero.
Input
One integer.
Output
One word.
Example
Input
5
Output
positive
Editor
C
Hints
You need three paths: if, else if and else.
Zero is neither greater nor less than 0.
Solution explanation
Each number falls into exactly one of the three branches.
Show solution
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
if (n > 0) {
printf("positive\n");
} else if (n < 0) {
printf("negative\n");
} else {
printf("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