C++ program to swap two numbers

#include<iostream>
using namespace std;


void swap(int & i,int & j);


int main()
   {
   int num1, num2;
   cout<<"Enter first Number :";
   cin>>num1;
   cout<<"Enter Second Number :";
   cin>>num2;
   cout<<endl<<endl;

    cout << "Before swapping:"<<endl;
    cout<<"First Number is = " << num1<<endl;

 cout<<"Second number is = " << num2<<endl<<endl;

    swap(num1,num2);

    cout << "After swapping"<<endl;
    cout<<" First number is =  " << num1 <<endl;

 cout<<" Second number is = " << num2 <<endl<<endl;


     return 0;

}
void swap(int& i, int& j)
{
    int t = i;
    i = j;
 j = t;
}


No comments:

Post a Comment