Skip to content
Home » C program to find whether the number is positive or negative using the conditional operator.

C program to find whether the number is positive or negative using the conditional operator.

Learn about C program to find whether the number is positive or negative using the conditional operator. in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C program to find whether the number is positive or negative using the conditional operator.

Program:

#include<stdio.h>
int main()
{
  int num;
  printf("Enter a number: ");
  scanf("%d", &num);
  (num>=0)?printf("Positive."):printf("Negative");
  return 0;
}

Output:

Enter a number: -3
Negative

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C program to find the maximum in the given two numbers using the conditional operator
C program to find the area of the circle, area of the triangle and area of the rectangle according to the user’s input choice