How to swap two numbers without using third variable in C Program?
How to swap two numbers without using third variable in C Program?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
#include<stdio.h>
int main() {
int a, b;
printf("\nEnter value for 1st number & 2nd number : ");
scanf("%d %d", &a, &b);
a = a + b;
b = a - b;
a = a - b;
printf("\nAfter swapping value of a : %d", a);
printf("\nAfter swapping value of b : %d", b);
return (0);
}
Program Output
Enter value for 1st number & 2nd number : 30 40
After swapping value of a : 40
After swapping value of b : 30