第一个方法实现:
#include <stdio.h>
int main()
{
float num;
printf("Enter a number: ");
scanf("%f",&num);
if (num<=0)
{
if (num==0)
printf("You entered zero.");
else
printf("%.2f is negative.",num);
}
else
printf("%.2f is positive.",num);
return 0;
}
用if...else...实现
#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("%.2f is negative.",num);
else if (num>0) /* Checking whether num is greater than zero*/
printf("%.2f is positive.",num);
else
printf("You entered zero.");
return 0;
} |
|