c语言中浮点double型数据的输入
001、double型数据的输入
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c ## 测试程序 #include <stdio.h> int main(void) { double vx; printf("vx = "); scanf("%lf", &vx); // double型数据的输入需要使用格式化字符串%lf printf("vx: %f\n", vx); return 0; } [root@PC1 test]# gcc test.c -o kkk ## 编译 [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk ## 运算测试 vx = 83.4 vx: 83.400000
.
002、float型数据的输入a
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c ## 测试程序 #include <stdio.h> int main(void) { float vx; printf("vx = "); scanf("%f", &vx); // 相对于double型数据的输入,float型数据输入可以使用格式化字符%f printf("vx: %f\n", vx); return 0; } [root@PC1 test]# gcc test.c -o kkk ## 编译 [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk ## 运算测试 vx = 34.3 vx: 34.299999
。
003、float型数据的输入是否可以使用格式化字符%lf?
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c #include <stdio.h> int main(void) { float vx; printf("vx = "); scanf("%lf", &vx); // float型数据尝试使用格式化字符%lf printf("vx: %f\n", vx); return 0; } [root@PC1 test]# gcc test.c -o kkk [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk ## 结果说明不可行 vx = 34.45 vx: -0.000000 [root@PC1 test]# ./kkk vx = 446 vx: 0.000000 [root@PC1 test]# ./kkk vx = 8.8 vx: -0.000000
。
double型数据的输入使用 %lf;
float型数据的输入使用%f;
。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2023-11-04 perl语言中 cpan 模块的安装
2023-11-04 version `GLIBC_2.34' not found (required by ./rmblastn)
2023-11-04 ./rmblastn: error while loading shared libraries: libzstd.so.1: cannot open shared object file: No such file or directory
2023-11-04 Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains
2022-11-04 linux shell 中实现基本的双循环
2022-11-04 linux 中输出参考基因组gff文件第9列的注释类别
2022-11-04 linux 中 awk命令中数组的应用