Wednesday 29 January 2020

simple method of swapping two numbers in cpp using third variable

Source Code:

#include<iostream>
using namespace std;
int main()
{
int temp,x,y;
cout<<"Enter X: ";
cin>>x;
cout<<"Enter Y: ";
cin>>y;
temp=x;
x=y;
y=temp;
cout<<"X = "<<x<<endl;
cout<<"Y = "<<y<<endl;
return 0;

}

 Program Output: 

No comments:

Post a Comment