/* Swapping Value : Exchanging values of two variables. */
#include <stdio.h>
int main()
{
int a, b, c;
printf("Enter two numbers you want to swap: ");
scanf("%d %d", &a, &b);
printf("Before Swapping:\nA = %d and B = %d\n", a, b);
// Swapping using third variable
c = a;
a = b;
b = c;
printf("After Swapping:\nA = %d and B = %d\n", a, b);
// Swapping without using third variable
a = a + b;
b = a - b;
a = a - b;
printf("Again After Swapping:\nA = %d and B = %d\n", a, b);
// Swapping without using third variable
a = a * b;
b = a / b;
a = a / b;
printf("Then Again After Swapping:\nA = %d and B = %d\n", a, b);
return 0;
}
Comments
Post a Comment