|
For any input number less than 1, find its number and output it separately. It is required to leave 2 spaces between the output numbers. For example, input 0.435 and the output is 0 4 3 5
#include <iostream>
using namespace std;
int main ()
{
float x;
int s;
cin >> x;
cout << 0 << "";
while (x! = 0)
{
s = x * 10;
cout << s << "";
x = x * 10-s;
}
return 0;
}
Why did I enter 0.435
The output is: 0 4 3 5 0 0 0 0 0 2 3 8 4
If I change the loop condition to while (x> 1e-6)
The output is the same. . .
what's up? |
|