csansoon

P1.10 P92351 Integer division and remainder of an integer

Sep 19th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.19 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6.     int a,b,d,r;
  7.     cin >> a >> b;
  8.     d=a/b;
  9.     r=a%b;
  10.     if (r<0) {
  11.         d=(d-1);
  12.         r=(a-(d*b));
  13.     }
  14.     cout << d << " " << r << endl;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment