是否可以使用ONE SINGLE语句从一组数字中打印C++中的随机数?
假设这个集是{2,5,22,55,332}
我查了一下rand()但是我怀疑它可以在一个声明中完成.
我写了以下程序:
#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)
为什么精度会发生变化?