How to output negative numbers in C language?

In C language, negative numbers can be represented by adding a minus sign “-” in front of the numerical value. The printf function can be used to output negative numbers to the screen. Here are some example codes:

#include <stdio.h>

int main() {
    int num = -10;
    printf("负数:%d\n", num);
    
    float fnum = -3.14;
    printf("负数:%f\n", fnum);
    
    return 0;
}

Output result:

负数:-10
负数:-3.140000

In the printf function, %d is used to display integers, and %f is used to display floating-point numbers.

bannerAds