c中int型和浮点型的格式话输出
001、
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c // 测试程序 #include <stdio.h> int main(void) { int i = 10; printf("i1 = %d\n", i); printf("i2 = %f\n", i); return 0; } [root@PC1 test]# gcc test.c -o kkk // 编译 [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk // %f不能转换int型数据 i1 = 10 i2 = 0.000000
002、
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c // 测试程序 #include <stdio.h> int main(void) { int i = 8.888; // 把int型给予浮点型数据 printf("i1 = %d\n", i); // %d转换 printf("i2 = %f\n", i); // %f转换 return 0; } [root@PC1 test]# gcc test.c -o kkk // 编译 [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk ## int型无法用%f转换 i1 = 8 i2 = 0.000000
。
003、
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c // 测试程序 #include <stdio.h> int main(void) { double i = 9.888; printf("i1 = %f\n", i); printf("i2 = %d\n", i); // 用%d转换double型 return 0; } [root@PC1 test]# gcc test.c -o kkk [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk ## 无法正常转换 i1 = 9.888000 i2 = 2147483634
。
004、
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c // 测试程序 #include <stdio.h> int main(void) { double i = 10; printf("i1 = %f\n", i); printf("i2 = %d\n", i); return 0; } [root@PC1 test]# gcc test.c -o kkk [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk ## %d无法转换double型数据 i1 = 10.000000 i2 = 2147483633
。
c语言中不能用%f输出int型数据; 其输出结果为0;
c语言中不能用%d输出double型数据,其输出无规则。
分类:
c/c++
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2022-07-27 R语言中对数据框进行排序
2022-07-27 R语言中inner_join、left_join、right_join、full_join函数
2022-07-27 R语言中如何删除重复行
2022-07-27 R语言中如何读取带有#注释的数据
2022-07-27 R语言读取数据如何跳过文件的前几行
2022-07-27 R语言中如何读取列数不一致的数据
2022-07-27 GWAS分析 一般线性模型GLM + 协变量中meta、se、T、p值的计算