Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Solved Programs » Program to swap two integer values wihout using third variable

C program to swap two integer values wihout using third variable

include <stdio.h>

int main()
{
//declare only two variables
int a, b;

printf("\n\nEnter the values of a : ");
scanf("%d",&a);
printf("\nEnter the values of b : ");
scanf("%d",&b);

printf("\nThe values before Swapping are \n");
printf("\n a : %d",a);
printf("\n b : %d",b);

//swapping logic
a = a * b;
b = a /b;
a = a /b;


printf("\n\n The values after Swapping are \n");
printf("\n a : %d",a);
printf("\n b : %d",b);

//hold the screen
getchar();

return 0;
}

Swapping of 4 & 5 without using third variable

C program to swap two integer values wihout using third variable