Number is Positive or Negative or Zero: C Program


C Program to check whether the user entered integer number is positive, negative or zero using else if construct.

Note:
Any number greater than 0 is positive.
Any number less than 0 is negative.

Check Whether Number is Positive or Negative or Zero: C Program


[youtube https://www.youtube.com/watch?v=lxNZZJ7NVlE]

YouTube Link: https://www.youtube.com/watch?v=lxNZZJ7NVlE [Watch the Video In Full Screen.]


Check Whether Number is Positive or Negative or Zero: C Program

#include < stdio.h >

int main()
{
    int a;

    printf("Enter an integer number\n");
    scanf("%d", &a);

    if(a > 0)
    {
        printf("%d is positive\n", a);
    }
    else if(a < 0)
    {
        printf("%d is negative\n", a);
    }
    else
    {
        printf("%d is zero\n", a);
    }

    return 0;
}

Output 1:
Enter an integer number
15
15 is positive

Output 2:
Enter an integer number
-2
-2 is negative

Output 3:
Enter an integer number
0
0 is zero

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

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