前言:
如今我们对“c语言浮点数转换成十六进制”可能比较重视,姐妹们都需要知道一些“c语言浮点数转换成十六进制”的相关资讯。那么小编在网摘上搜集了一些有关“c语言浮点数转换成十六进制””的相关文章,希望小伙伴们能喜欢,小伙伴们一起来学习一下吧!printf()函数为IO函数,请求print()打印变量的指令取决于变量的类型。诸如,我们在打印int型的时候需使用%d符号,在打印字符的时候需使用%c符号。这些符号被称之为转换说明,它指定了如何把数据转换成可显示的形式。下面就来看看ANSI C标准为print()提供的各种转换说明。
转换说明%a 浮点数、十六进制数字和p-计数法%A 浮点数、十六进制数字和p-计数法
double num = 512.0;
printf("num is %a\n",num);
printf("num is %A\n", num);
结果:
num is 0x1.0000000000000p+9
num is 0X1.0000000000000P+9
%c 一个字符
char a = 'a';
printf("a is %c\n", a);
结果:
a is a
%d 有符号十进制整数%i 有符号十进制整数
int b = 512;
printf("b is %d\n", b);
printf("b is %i\n", b);
结果:
b is 512
b is 512
%e 浮点数、e-计数法%e 浮点数、e-计数法
double c = 512.0;
printf("c is %e\n", c);
printf("c is %E\n", c);
结果:
c is 5.120000e+02
c is 5.120000E+02
% f 浮点数 十进制计数法
double d = 512.0;
printf("d is %f\n", d);
结果:
d is 512.000000
%G 根据数据的不同自动选择%f或者%e。%e格式在指数小于-4或者大于等于精度。%g 根据数据的不同自动选择%f或者%e。%e格式在指数小于-4或者大于等于精度。
double e = 512.0;
printf("e is %g\n", e);
printf("e is %G\n", e);
结果:
e is 512
e is 512
%o 无符号八进制整数
int f = 8;
printf("f is %o\n", f);
结果:
f is 10
%p 指针
int g = 10;
int * h = &g;
printf("h adr is %p\n", h);
printf("h is %d\n", *h);
结果:
h adr is 0133FB68
h is 10
%s 字符串
char i[] = "i love you";
printf("%s\n", i);
结果:
i love you
%u 无符号十进制整数
int j = 256;
printf("j is %u\n", j);
结果:
j is 256
%x 使用十六进制数字0f的无符号十六进制整数%X 使用十六进制数字0F的无符号十六进制整数
int k = 16;
printf("k is %x\n", k);
printf("k is %X\n", k);
结果:
k is 10
k is 10
%% 打印一个百分号
float m = 0.04;
printf("m is %d %%\n", int(m*100));
结果:
m is 4 %
#include <stdio.h>
int main()
{
double num = 512.0;
printf("num is %a\n",num);
printf("num is %A\n", num);
char a = 'a';
printf("a is %c\n", a);
int b = 512;
printf("b is %d\n", b);
printf("b is %i\n", b);
double c = 512.0;
printf("c is %e\n", c);
printf("c is %E\n", c);
double d = 512.0;
printf("d is %f\n", d);
double e = 512.0;
printf("e is %g\n", e);
printf("e is %G\n", e);
int f = 8;
printf("f is %o\n", f);
int g = 10;
int * h = &g;
printf("h adr is %p\n", h);
printf("h is %d\n", *h);
char i[] = "i love you";
printf("%s\n", i);
int j = 256;
printf("j is %u\n", j);
int k = 16;
printf("k is %x\n", k);
printf("k is %X\n", k);
float m = 0.04;
printf("m is %d %%\n", int(m*100));
return 0;
}
喜欢我文章的朋友,欢迎关注、点赞、评论、交流。
标签: #c语言浮点数转换成十六进制 #浮点数转换16进制 c语言 #c语言百分号什么意思