C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Decision Making Programs in C

Check whether a number is Positive, Negative, or Zero

Introduction

In mathematics:

  • A positive number is greater than 0.
  • A negative number is less than 0.
  • Zero is neither positive nor negative.

This program reads a number from the user and determines whether it is positive, negative, or zero using an if-else decision-making structure.

 

C Program: Check whether a number is Positive, Negative, or Zero

C

#include <stdio.h>

 

int main() {

    int num;

 

    // Input from user

    printf("Enter a number: ");

    scanf("%d", &num);

 

    // Check conditions

    if (num > 0) {

        printf("%d is Positive.\n", num);

    }

    else if (num < 0) {

        printf("%d is Negative.\n", num);

    }

    else {

        printf("The number is Zero.\n");

    }

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter a number: 25
25 is Positive.

OUTPUT 2 :
Enter a number: -10
-10 is Negative.

OUTPUT 3 :
Enter a number: 0
The number is Zero.
 

Explanation

  1. User enters an integer.
  2. Program checks:
    • If num > 0 → positive
    • Else if num < 0 → negative
    • Else → zero
  3. Prints the result accordingly.