洛克老師請幾位同學上台寫 7除以3 是多少
請問誰的寫法才是正確的?
想好以後往下捲。
生活中根據應用狀況的不同,同一個問題本來就會有不同的答案。
在C++的世界中也是如此,C++有不同的寫法對應每一種除法的狀況。
#include<iostream>
using namespace std;
int main()
{
cout << 7/3 << endl;
return 0;
}
2
#include<iostream>
using namespace std;
int main()
{
cout << 7.0/3 << endl;
cout << 7/3.0 << endl;
return 0;
}
2.33333
2.33333
#include<iostream>
using namespace std;
int main()
{
cout << "7/3" << endl;
return 0;
}
7/3