C语言中的%0nd,%nd,%-nd

C语言中的%0nd

printf --> formatted print/格式化输出

一、十进制

d -> decimal/十(shí)进制

    int a=1;  
    int b=1234;  
    double c=1.2345678;  
    printf("%2d\n",a);  
    printf("%+2d\n",a);  //在前面补充‘+’号
    printf("%4d\n",a); // 在前面补空格 
    printf("%-4d\n",a); // 在后面补空格 
    printf("%2d\n",b);  
    printf("%+2d\n",b);  
    printf("%4d\n",b);   
    printf("%2.2f\n",c);  

结果如下:

二、十六进制%x

x -> hexadecimal,其中hexadecimal来自于古希腊,这个词语 is composed of hexa-, derived from the Greek έξ (hex) for six, and -decimal, derived from the Latin for tenth.

三、八进制%o

o -> octal; [1935–40; < Latin oct(ō) or Greek okt(ṓ) eight + -al1]

参考:
1、Print formatted data to stdout

posted @ 2016-09-09 11:19  xiulug  阅读(1544)  评论(0编辑  收藏  举报