If
a number is greater than 0 then that number is a positive.
If
a number is less than 0 then the number is negative.
Here
the C Program checks if a given number is positive or negative. It can be compiled
and run on any system.
Method 1:
#include
<stdio.h>
int
main()
{
float
num;
printf("Enter
a number: ");
scanf("%f",&num);
if
(num<=0) {
if
(num==0)
printf("\n\nYou
entered zero which is neither positive nor negative.\n\n");
else
printf("\n\n%.2f
is negative.\n\n",num);
}
else
printf("\n\n%.2f
is positive.\n\n",num);
return
0;
#include
<stdio.h>
int
main()
{
float
num;
printf("Enter
a number: ");
scanf("%f",&num);
if
(num<0) /* Checking whether num
is less than 0*/
printf("\n\n%.2f
is negative.\n\n",num);
else
if (num>0) /* Checking whether num
is greater than zero*/
printf("\n\n%.2f
is positive.\n\n",num);
else
printf("\n\nYou
entered zero which is neither positive nor negative.\n\n");
return
0;
}