Swap Two Numbers
Take two numbers as input and swap them and print the swapped values.
Input Format:
The first line of input contains a single integer 't', representing the total number of test cases.
The second line of input contains two integers 'a' and 'b', representing the second number.
Output Format:
The first line of output prints the swapped value of 'a' and 'b'.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= 'T' <= 10^2
-10^5 <= 'a', 'b' <= 10 ^ 5
Time Limit: 1 sec
CodingNinjas
author
2y
Approach 1 (Using Destructruring Assignment) : This method was specific only for JS and the interviewer was preety
impressed when I used it .
Destructuring assignment (a feature of ES2015) lets you extr...read more
CodingNinjas
author
2y
Swapping using a temporary variable
Take input in two integer datatype variables, a and b. Create a temporary variable temp and initialize it equal to a. Now make a equal to b, and finally make b equal...read more
CodingNinjas
author
2y
Using arithmetic operation
We can swap values of two variables by using a third variable and instead of that, we can use the arithmetic operation to do it without an extra variable.
The idea is to store...read more
Add answer anonymously...
Top Cybage React Developer interview questions & answers
Popular interview questions of React Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app