Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void calculate(int p, int q);
  6.  
  7. int n;
  8. int p[1000], q[1000];
  9.  
  10. int main() {
  11.  
  12.     //cout<<"Starting..."<<endl;
  13.  
  14.     cin>>n;
  15.    
  16.     for( int i=0; i<n; i++) {
  17.         cin>>p[i];
  18.         cin>>q[i];
  19.     }
  20.    
  21.     for( int i=0; i<n; i++) {
  22.         calculate(p[i], q[i]);
  23.     }
  24.  
  25.     //system("pause");
  26.     return 0;
  27. }
  28.  
  29. void calculate(int p, int q) {
  30.  
  31.    
  32.     /*if(p!=1) {*/
  33.         int a=p;
  34.         p=q;
  35.         q=a;
  36.  
  37.         int w = p/q;
  38.         cout << w << " ";
  39.         p = p - (q*w);
  40.         /*if(q>1)*/ calculate(p, q);
  41.    
  42.     /* } else {
  43.         cout << q << endl;
  44.     }*/
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement