小编Har*_*han的帖子

一组中的C++随机数

是否可以使用ONE SINGLE语句从一组数字中打印C++中的随机数?

假设这个集是{2,5,22,55,332}

我查了一下rand()但是我怀疑它可以在一个声明中完成.

c++ random srand

4
推荐指数
3
解决办法
9512
查看次数

为什么C浮点类型会在输出时修改125.1到125.099998的实际输入?

我写了以下程序:

 #include<stdio.h>
    int main(void)
    {
     float f;
     printf("\nInput a floating-point no.: ");
     scanf("%f",&f);
     printf("\nOutput: %f\n",f);
     return 0;
    }
Run Code Online (Sandbox Code Playgroud)

我在Ubuntu上并使用GCC编译上述程序.这是我想要查询的示例运行和输出:

Input a floating-point no.: 125.1
Output: 125.099998
Run Code Online (Sandbox Code Playgroud)

为什么精度会发生变化?

c floating-point

1
推荐指数
2
解决办法
959
查看次数

标签 统计

c ×1

c++ ×1

floating-point ×1

random ×1

srand ×1