C++ Programe To Swap Two Variables Without Using Third Variable
/*C++ Programe To Swap Two Variables Without Using Third Variable*/
/****************First Method******************************/
#include<iostream>
using namespace std;
int main()
{int a,b;
cout<<"Enter The Value Of A:--";
cin>>a;
cout<<"Enter The Value Of B:--";
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"After Swaping:--";
cout<<"\nA:--"<<a;
cout<<"\nB:--"<<b;
return 0;
}
/******************Second Method**************************/
#include<iostream>
using namespace std;
int main()
{int a,b;
cout<<"Enter The Value Of A:--";
cin>>a;
cout<<"Enter The Value Of B:--";
cin>>b;
a=a*b;
b=a/b;
a=a/b;
cout<<"After Swaping:--";
cout<<"\nA:--"<<a;
cout<<"\nB:--"<<b;
return 0;
}
/*C++ Programe To Swap Two Variables Without Using Third Variable*/
/****************First Method******************************/
#include<iostream>
using namespace std;
int main()
{int a,b;
cout<<"Enter The Value Of A:--";
cin>>a;
cout<<"Enter The Value Of B:--";
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"After Swaping:--";
cout<<"\nA:--"<<a;
cout<<"\nB:--"<<b;
return 0;
}
/******************Second Method**************************/
#include<iostream>
using namespace std;
int main()
{int a,b;
cout<<"Enter The Value Of A:--";
cin>>a;
cout<<"Enter The Value Of B:--";
cin>>b;
a=a*b;
b=a/b;
a=a/b;
cout<<"After Swaping:--";
cout<<"\nA:--"<<a;
cout<<"\nB:--"<<b;
return 0;
}
0 Comments