C program using + and - operators to swap two numbers without using a third variable #include<stdio.h> int main() { int a = 10, b = 40; printf("Before swap: a = %d ; b = %d\n", a, b); a = a + b; // a = 50 b = a - b; // b = 10 a = a - b; // a = 40 printf("After swap: a = %d ; b = %d\n", a, b);Read more
C program using + and – operators to swap two numbers without using a third variable
#include<stdio.h>
int main()
{
int a = 10, b = 40;
printf("Before swap: a = %d ; b = %d\n", a, b);
a = a + b; // a = 50
b = a - b; // b = 10
a = a - b; // a = 40
printf("After swap: a = %d ; b = %d\n", a, b);
return 0;
}
How to Swap Two Numbers in C without Using Third Variable: 3 Simple Methods
C program using + and - operators to swap two numbers without using a third variable #include<stdio.h> int main() { int a = 10, b = 40; printf("Before swap: a = %d ; b = %d\n", a, b); a = a + b; // a = 50 b = a - b; // b = 10 a = a - b; // a = 40 printf("After swap: a = %d ; b = %d\n", a, b);Read more
C program using + and – operators to swap two numbers without using a third variable
#include<stdio.h> int main() { int a = 10, b = 40; printf("Before swap: a = %d ; b = %d\n", a, b); a = a + b; // a = 50 b = a - b; // b = 10 a = a - b; // a = 40 printf("After swap: a = %d ; b = %d\n", a, b); return 0; }
See less