fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7. float n = 5.9999;
  8. cout << n - (int)n;
  9. int s = 0;
  10. while (n > 1){
  11. n -= (int)n;
  12. n *= 10;
  13. s += (int)n;
  14. cout << n << ' ' << s << endl;
  15. }
  16. cout << s;
  17. return 0;
  18. }
Success #stdin #stdout 0.01s 5320KB
stdin
4.999
stdout
0.99999.999 9
9.98999 18
9.89986 27
8.99864 35
9.98642 44
9.8642 53
8.64197 61
6.41968 67
4.19678 71
1.96777 72
9.67773 81
6.77734 87
7.77344 94
7.73438 101
7.34375 108
3.4375 111
4.375 115
3.75 118
7.5 125
5 130
0 130
130