输入两个double型的数,输出谁大谁小,如果差异小于0.01输出两者相差不大?
#include "../std_lib_facilities.h"
int main()
{
double ia, ib;
while (cin>>ia>>ib)
{
if (ia < ib) {
cout << "The smaller value is:" << ia << '\n'
<< "The larger value is:" << ib << '\n';
cout << ib - ia << '\n';
cout << 1.0 / 100 << '\n';
cout << (ib - ia) - 1.0 / 100 << '\n';
if (ib - ia < 1.0 / 100)
cout << "the numbers are almost equal.\n";
}
else if (ia > ib) {
cout << "The smaller value is:" << ib << '\n'
<< "The larger value is:" << ia << '\n';
if (ia - ib < 1.0 / 100)
cout << "the numbers are almost equal\n";
}
else
cout << "the numbers are equal\n";
}
}
输入3.1 3.11
输出为:
The smaller value is:3.1 The larger value is:3.11 0.01 0.01 -2.13371e-16 the numbers are almost equal.?
|