Advertisement
vaibhav1906

C++ Call by reference | Gammaprep solution

Sep 10th, 2021
1,286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5.  // } Driver Code Ends
  6. //User function Template for C++
  7.  
  8. void reverse_dig(int &a,int &b)
  9. {
  10.     //Add your code here.
  11.     int x=0,y=0;
  12.     while(a!=0){
  13.         x = x*10 + (a%10);
  14.         a/=10;
  15.     }
  16.     while(b!=0){
  17.         y = y*10 + (b%10);
  18.         b/=10;
  19.     }
  20.     a= x;
  21.     b = y;
  22.    
  23.     return;
  24. }
  25. void swap(int &a,int &b)
  26. {
  27.     int c;
  28.     c = a;
  29.     a = b;
  30.     b=c;
  31.     return;
  32.     //Add your code here.
  33. }
  34.  
  35.  
  36. // { Driver Code Starts.
  37.  
  38. int main()
  39. {
  40.     int t;
  41.     cin>>t;
  42.     while(t--)
  43.     {
  44.         int a, b;
  45.         cin>>a>>b;
  46.    
  47.         reverse_dig(a,b);
  48.         swap(a,b);
  49.         cout<<a<<" "<<b<<endl;
  50.     }
  51.     return 0;
  52. }  //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement