译文: https://beginnersbook.com/2015/02/c-program-to-check-whether-the-given-integer-is-positive-or-negative/

    在下面的程序中,我们检查输入整数是正数还是负数。如果输入数字大于零,则其为正数,否则为负数。如果数字为零则既不是正数也不是负数。我们在下面的 C 程序中遵循了相同的逻辑。

    1. /* Description: A program to check whether the input
    2. * integer number is positive or negative.
    3. * Written by: Chaitanya Singh
    4. * Published on: beginnersbook.com
    5. */
    6. #include <stdio.h>
    7. void main()
    8. {
    9. int num;
    10. printf("Enter a number: \n");
    11. scanf("%d", &num);
    12. if (num > 0)
    13. printf("%d is a positive number \n", num);
    14. else if (num < 0)
    15. printf("%d is a negative number \n", num);
    16. else
    17. printf("0 is neither positive nor negative");
    18. }

    输出 1:

    1. Enter a number:
    2. 0
    3. 0 is neither positive nor negative

    输出 2:

    1. Enter a number:
    2. -3
    3. -3 is a negative number

    输出 3:

    1. Enter a number:
    2. 100
    3. 100 is a positive number