CPP   25

myswap

Guest on 20th April 2022 01:59:19 AM

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void myswap(int &a, int &b){
  5.     int temp;
  6.  
  7.     temp=a;
  8.     a=b;
  9.     b=temp;
  10. }
  11.  
  12.  
  13. int main() {
  14.     int a=10;
  15.     int b=20;
  16.  
  17.     cout << "a: " << a << endl;
  18.     cout << "b: " << b << endl;
  19.     myswap(a,b);
  20.  
  21.     cout << endl;
  22.  
  23.     cout << "a: " << a << endl;
  24.     cout << "b: " << b << endl;
  25.  
  26.     return 0;
  27. }

Raw Paste


Login or Register to edit or fork this paste. It's free.