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;

。 

 

posted @   小鲨鱼2018  阅读(39)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!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命令中数组的应用
点击右上角即可分享
微信分享提示