C Program to Check Positive, Negative, or Zero

Written: August 14, 2026 · Updated: August 15, 2026

Branching on the sign of a number is a classic first if-else lab in C and GTU coursework.

This walkthrough keeps the logic small and readable so you can type it, run it, and then change one input at a time to see what happens.

What you will build

Read one integer and print whether it is positive, negative, or exactly zero.

  • Read an integer n
  • If n > 0 print positive
  • Else if n < 0 print negative
  • Else print zero

Working C example

include <stdio.h>

int main(void) {
    int n;
    printf("Enter an integer: ");
    if (scanf("%d", &n) != 1) return 1;
    if (n > 0) {
        printf("Positive\n");
    } else if (n < 0) {
        printf("Negative\n");
    } else {
        printf("Zero\n");
    }
    return 0;
}

Advertisement

How the logic works

Read the program top to bottom: includes and main first, then the statements that change variables, then the print that proves the result.

If your output looks wrong, print the variables before and after the critical lines. That single habit catches most beginner bugs faster than rewriting the whole file.

Test 5, -3, and 0. Zero is the case beginners accidentally fold into “positive.”.

Advertisement

Keep learning

If this walkthrough on C Program to Check Positive, Negative, or Zero helped, open the code again and change one input or assumption. Small experiments beat rereading the same example.

Want more step-by-step tutorials like this? Browse blog.xqa.io — and tell us which topic you want next.

Advertisement

Previous Article

Sort an Array in Ascending Order in C

Next Article

Find the Maximum Element in a 1D Array in C

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨