Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经尝试了一切。当我输入 1/5 = a 并尝试显示 a 时,此终端正在工作,它会说它是 0。或者即使我尝试 25/10(假设为 2.5),它也会显示 2。我尝试使用浮点数,双数,整数。一切。请帮我。
1、5、25、10是整数,所以用它们计算会产生整数结果。尝试double x = 1.0/5.0和double y = 25.0/10.0。
double x = 1.0/5.0
double y = 25.0/10.0
#include<iostream> using namespace std; int main() { float a; a=(float)1/5; cout << a << endl; }