Sunday, 13 March 2016

Write A C++ Program For Swaping Two Number In Function Using Pointer

#include
using namespace std;

void swap(int&, int&);    

int main()
{
//Ghanendra Yadav
    int a = 1, b = 2;
    cout << "Before swapping" << endl;
    cout<<"Enter The Two Value \n";
    cin>>a>>b;

    swap(a, b);

    cout << "\nAfter swapping" << endl;
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;
    return 0;
}

void swap(int& n1, int& n2)
{
    int temp;
    temp = n1;
    n1 = n2;
    n2 = temp;
}

Output:-


No comments:
Write comments

Recommended Posts × +