Advertisement
knyazer

Untitled

Jan 6th, 2021
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void print(double x)
  6. {
  7.     if (x < 0)
  8.     {
  9.         cout << '-';
  10.         x = -x;
  11.     }
  12.  
  13.     cout << int(x);
  14.     cout << '.';
  15.     x -= int(x);
  16.    
  17.     for (int i = 0; i < 9; i++)
  18.     {
  19.         x *= 10;
  20.         cout << int(x) % 10;
  21.         if (abs(x - int(x)) < 1e-6)
  22.             break;
  23.     }
  24.  
  25.     cout << endl;
  26. }
  27.  
  28. int main()
  29. {
  30.     double n = 0;
  31.     while (n < 2)
  32.     {
  33.         print(n);
  34.         n += 0.0001;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement