![Write a C Program to Swap the values of two variables Swap the values of two variables, without using third variable, Sumit Kar, Timus Rak, XOR](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgEEuiVQujzDYGlv1PMDzDKYb5ozvCbIjo_Mt3FOu_A8h6GVex9UkCglRQEuc0wTKxbm_OgzCSMsAl0xTsTrdYwnZVmL3fFis99MAlE7B7SZTE3u-l8-Yoy14a7zhjLCMXS_y2grkLeaBz/s1600/c-programming-tutorial.jpg)
/* Swap the values of two variables using three variable */
#include<stdio.h>
void main()
{
int a;
int b;
int c;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
c=a;
a=b;
b=c;
printf("A : %i",a);
printf("\nb : %i",b);
}
/* Swap the values of two variables without using third variable */
#include<stdio.h>
void main()
{
int a;
int b;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
a=a+b;
b=a-b;
a=a-b;
printf("A : %i",a);
printf("\nb : %i",b);
}
/* Swap values of two variables using XOR */
#include<stdio.h>
void main()
{
int a;
int b;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
a ^= b;
b ^= a;
a ^= b;
printf("A : %i",a);
printf("\nB : %i",b);
}
0 Comments