Saturday, 18 March 2017

Geeksforgeeks Solution For " Swap two numbers "

GeeksforGeeks Solution For School Domain .Below You Can Find The Solution Of Basic ,Easy ,Medium ,Hard .You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Swap given two numbers and print them. (Try to do it without a temporary variable.)

Submit Your Solution :- Click Here 


Solution :- 

#include <iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    int a,b;
    cin>>a>>b;
    a=a+b;
    b=a-b;
    a=a-b;
    
    cout<<a<<" "<<b<<endl;
    }
    return 0;
}

Output:-


Geeksforgeeks Solution For " Swap two numbers "

No comments:
Write comments

Recommended Posts × +