Online Snippets Library

Check if a given number is positive or negative in C

To Check given number is positive or negative, We need compare number with zero, if number is greater and equal to zero then number is postive else number is negative.

C Program
#include <stdio.h>

int main() {
   int number = -4;
   
   if (number >= 0)
      printf("%d is positive\n", number);
   else
      printf("%d is negative\n", number);
   
   return 0;
}

Output

-4 is negative