C program to check whether a number is positive, negative or zero

Write a C program to check positive, negative or zero. Program to input any number from user and check whether the given number is positive, negative or zero. How to check negative, positive or zero using if else in C program.

Input number: 23
Output: Positive number

Required knowledge

Basic programming, Basic mathematics, Use of relational operator, If else

Logic to check positive, negative or zero

Checking positive, negative or zero is an easy task if you know basic maths. A number is said to be negative if it is less than 0 i.e. (n < 0) (Where n is the number)
A number is said to be positive if it is greater than 0 i.e. (n > 0)
Hence here in this program to check positive, negative or zero we only need to check whether the number is greater that 0 or not.

Program to check positive, negative or zero

 * C program to check positive negative or zero

#include <stdio.h>

int main()
    int num;
    /* Read number from user */
    printf("Enter any number: ");
    scanf("%d", &num);

    if(num > 0)
        printf("Number is POSITIVE");
    else if(num < 0)
        printf("Number is NEGATIVE");
        printf("Number is ZERO");

    return 0;

Enter any number: 10
Number is POSITIVE

Happy coding ;)

Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

1 comment:

  1. Basic C Program for Computer Programmer who want to learn. If you have simple wish you may visit. To get all update stay with us.
    • Language: C and Simscript.
    • if (Condition) statement and Nested if statement is used to determine the given number is positive, negative, even or odd. Another way we solve this program using if-else-if ladder.
    • When the given condition or expression is true the statement associated with it executed.
    To know details: