#include stdio.hint main( void ){float d1 = 10000.123;int n, f;char *m1 = Binary;
编程学习网为您整理以下代码实例,主要实现:printf()打印十六进制,八进制,十进制,二进制数字段宽度,希望可以帮到各位朋友。
#include <stdio.h>
int main( voID )
{
float d1 = 10000.123;
int n, f;
char *m1 = "Binary";
char *m2 = "Decimal";
char *m3 = "Octal";
char *m4 = "Hexadecimal";
puts("Outputting a number with different fIEld wIDths.\n");
printf("%5f\n", d1);
printf("%10f\n", d1);
printf("%15f\n", d1);
printf("%20f\n", d1);
printf("%25f\n", d1);
fflush(stdin);
puts("\nUse the * fIEld wIDth specifIEr to obtain fIEld wIDth");
puts("from a variable in the argument List.\n");
for (n=5;n<=25; n+=5)
printf("%*f\n", n, d1);
puts("\n Press Enter to continue...");
fflush(stdin);
getchar();
puts("\nInclude leading zeros.\n");
printf("%05f\n", d1);
printf("%010f\n", d1);
printf("%015f\n", d1);
printf("%020f\n", d1);
printf("%025f\n", d1);
fflush(stdin);
puts("\ndisplay in octal, decimal, and hexadecimal.");
puts("Use # to precede octal and hex output with 0 and 0X.");
puts("Use - to left-justify each value in its fIEld.");
printf("%-15s%-15s%-15s", m2, m3, m4);
for (n = 1;n< 20; n++)
printf("\n%-15d%-#15o%-#15X", n, n, n);
fflush(stdin);
puts("\n\nUse the %n conversion command to count characters.\n");
printf("%s%s%s%s%n", m1, m2, m3, m4, &n);
printf("\n\nThe last printf() output %d characters.\n", n);
return 0;
}
沃梦达教程
本文标题为:printf()打印十六进制,八进制,十进制,二进制数
基础教程推荐
猜你喜欢
- 明确指定任何或所有枚举数的整数值 1970-01-01
- C++输入/输出运算符重载 1970-01-01
- C++按值调用 1970-01-01
- end() 能否成为 stl 容器的昂贵操作 2022-10-23
- C++ #define 1970-01-01
- 分别使用%o和%x以八进制或十六进制格式显示整 1970-01-01
- 使用scanf()读取字符串 1970-01-01
- C++定义类对象 1970-01-01
- 初始化变量和赋值运算符 1970-01-01
- C语言访问数组元素 1970-01-01