Advertisement
ismaeil

B. Arithmetic Exercise 2

Aug 5th, 2022
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1.  ll x, y, k ;
  2.  
  3.     cin >> x >> y >> k ;
  4.  
  5.     cout<<x / y <<".";
  6.  
  7.     string s ;
  8.  
  9.     ll rem = x % y ;
  10.  
  11.     for (int i = 1 ; i<= k + 1 ; i++)
  12.     {
  13.         rem *= 10 ;
  14.  
  15.         int c = rem / y ;
  16.  
  17.         s += (char)(c + '0') ;
  18.  
  19.         rem %= y ;
  20.     }
  21.  
  22.     if (s.back() >= '5')
  23.         s[s.size() - 2]++;
  24.  
  25.     s.pop_back() ;
  26.  
  27.     cout<<s<<"\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement