Write a program to swap two numbers without using third variable
Program to swap two numbers without using third variable
Use the XOR operation to swap the numbers
Assign the first number to the second number using XOR
Assign the second number to the first number usin...read more
#include(stdio.h)
int main()
{
int a=10,b=20;
printf("before swap a=%d b=%d",a,b)
a=a+b;
b=a-b;
a=a-b;
printf("after swap a=%d b=%d",a,b);
return 0;
}
#include <stdio.h>
int main(){ int a, b; printf("Input two integers (a & b) to swap\n"); scanf("%d%d", &a, &b); a = a + b; b = a - b; a = a - b;
printf("a = %d\nb = %d\n",a,b); return 0;}
# Python code to swap two numbers
# without using third variable
x = 5
y = 7
print ("Before swapping: ")
print("Value of x : ", x, " and y : ", y)
# code to swap 'x' and 'y'
x, y = y, x
only logic
#include......
{
- a = a + b;
- b = a - b;
- a = a - b;
}
Top TCS Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in TCS Software Engineer
Reviews
Interviews
Salaries
Users/Month