我是 C++ 的新用户,我想知道为什么我的计算会产生极其荒谬的结果。这是我遇到问题的代码部分。
printf("Please enter the length of side:\n");
scanf("%.f", &lengthCube);
volume=lengthCube*lengthCube*lengthCube;
printf("The volume of this cube is %.f", volume);
volume
和 lengthCube
都被定义为 float
值。此处的测试值为 10,给出的答案为 -13798...(一个非常非常长的数字)。对此问题的任何帮助将不胜感激。谢谢!
最佳答案
您为 scanf
和 printf
使用了错误的格式 - 它应该是 "%f"
,而不是 "%。 f"
。
关于c - float 给出非常大的答案(C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30120606/