Swapping function in c++

Swapping function in c++

 #include<iostream>

using namespace std;

void swapnum(int& a, int& b){
    cout<<"Before swaping: "<<endl;
    cout<<"a = "<<a<<","<<"b = "<<b<<endl;
    int temp = a;
    a = b;
    b = temp;
    cout<<"After swaping: "<<endl;
    cout<<"a = "<<a<<","<<"b = "<<b<<endl;
}

int main(){
    int x = 12;
    int y = 4;
   swapnum(x, y);
   

    return 0;
}

Post a Comment

0 Comments