How To Swap Two Numbers Using Fuction In C++

#include <iostream>
#include <conio.h>
using namespace std;
void swaping(int&x,int&y);
int main()
{
    int a=100,b=200;
    cout<<"before swap, value of a="<<a<<endl;
    cout<<"before swap, value of b="<<b<<endl;
    swap(a,b);
    cout<<"after swap,value of a="<<a<<endl;
    cout<<"after swap,value of b="<<b<<endl;

    return 0;
}
 void swap (int&x,int&y)
{ int temp;
temp=x;
x=y;
y=temp;

return ;}

No comments:

Post a Comment