C Program to Check if a given Integer is Positive or Negative

C Programming Computer Science

In this C Program, we are going to find whether the given Integer is positive or negative.

  • Source Code

#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
        printf("%d is a negative number \n", num);
}

 

  • Runtime
Case:1
Enter a number
-87
-87 is a negative number
 
Case:2
Enter a number
72
72 is a positive number

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.