C Program That Determines Whether A Given Integer Is Positive Or Negative

The following program determines whether the integer number input is positive or negative. If the input number is greater than zero, it is positive; otherwise, it is negative. If the number is zero, it indicates that it is neither positive nor negative. The same logic is used in the C program below.

/* Description: A program to check whether the input
 * integer number is positive or negative. 
 * Written by: Chaitanya Singh
 * Published on: beginnersbook.com
#include <stdio.h>
void main()
    int num;
    printf("Enter a number: \n");
    scanf("%d", &num);
    if (num > 0)
        printf("%d is a positive number \n", num);
    else if (num < 0)
        printf("%d is a negative number \n", num);
        printf("0 is neither positive nor negative");

Output 1:

Enter a number:
0 is neither positive nor negative

Output 2:

Enter a number:
-3 is a negative number

Output 3:

Enter a number:
100 is a positive number

Related Articles

Leave a Reply

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

Back to top button