Friday, April 17, 2020

C++ program swapping of two numbers without using 3rd variable

Do you know to swap using 3rd variable ?
If yes then learn who to swap without using 3rd variable


#include<iostream>
using namespace std;
void main()
{
//Swapping without 3rd variable
 int a=10,b=20; //Value of a=10 and b=20
 cout<<"Value of 'a' before Swapping: "<<a<<endl;
 cout<<"Value of 'b' before Swapping: "<<b<<endl;
 a=a+b;     //now a=a(10)+b(20) -> a=30
 b=a-b;     //now b=a(30)-b(20) -> b=10
 a=a-b;     //now a=a(30)-b(10) -> a=20
 cout<<"Value of 'a' after swapping: "<<a<<endl;
 cout<<"Value of 'b' after swapping: "<<b<<endl;
system("pause");
}
Link of Video for more help::
https://youtu.be/9PYADBSffQ0


No comments:

Post a Comment

Maximum No

//Find the Maximum No between Three Nos' int i=10,o=20,k=30; if(i>o &&i>k) { cout<<"1st is g\n";...