C Program to Check Whether a Number is Positive, Negative or Zero

  • Write a C program to read a number and check whether number is positive, negative or zero.
  • Wap in C to check whether a number is negative, zero or positive using if else ladder.

Required Knowledge

We will first take an integer as input from user using scanf function. Then we check whether input number is positive, negative or zero using if else ladder statement.


C program to check whether an integer is negative, positive or zero

/** 
 * C program to check whether a number is 
 * positive, negative or zero
 */  
  
#include <stdio.h>  
  
int main() {  
    int number;  
    /* 
     * Take a number as input from user 
     */  
    printf("Enter a Number\n");  
    scanf("%d", &number);  
      
    if(number > 0) {  
        printf("%d is Positive Number", number);  
    } else if (number < 0) {  
        printf("%d is Negative Number", number);  
    } else {  
        printf("Input Number is Zero");  
    }  
    
    return 0;  
}

Output
Enter a Number
5
5 is Positive Number
Enter a Number
-3
-3 is Negative Number
Enter a Number
0
Input Number is Zero

Related Topics
C program to check whether a number is odd or even using switch statement
C program to check whether an alphabet is a vowel or consonant
C program to check year is leap year or not
C program to check whether three sides of triangle is valid or not
C program to check whether a triangle is equilateral, isosceles or scalene.
C program to check whether a triangle is equilateral, isosceles or scalene
C program to check a number is palindrome or not
C program to check whether a number is prime or not
C program to check if two strings are anagram
List of all C programs