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 and Even or Odd

Introduction

In this extended program:

  • First, we check if a number is positive, negative, or zero.
  • Then, if the number is not zero, we also check whether it is even or odd using the modulus operator %.

 

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

C

#include <stdio.h>

 

int main() {

    int num;

 

    // Input from user

    printf("Enter a number: ");

    scanf("%d", &num);

 

    // Check if number is zero

    if (num == 0) {

        printf("The number is Zero (neither Positive nor Negative, neither Even nor Odd).\n");

    }

    else {

        // Check positive or negative

        if (num > 0) {

            printf("%d is Positive and ", num);

        } else {

            printf("%d is Negative and ", num);

        }

 

        // Check even or odd

        if (num % 2 == 0) {

            printf("Even.\n");

        } else {

            printf("Odd.\n");

        }

    }

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter a number: 12
12 is Positive and Even.

OUTPUT 2 :
Enter a number: -7
-7 is Negative and Odd.

OUTPUT 3 :
Enter a number: 0
The number is Zero (neither Positive nor Negative, neither Even nor Odd).
 

Explanation

  1. If the number is 0 → it’s neither positive/negative nor even/odd.
  2. If not zero →
    • Use if (num > 0) → positive
    • Else → negative
    • Then check num % 2 == 0 → even, else odd.
  3. Print result clearly.