Swap of two numbers without using third variable
In this program we learn how to swap of two numbers without using third variable provided by user using C.C program to swap of two numbers without using third variable
// Swap of two numbers without using third variable
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
clrscr();
printf("\n Enter two number : ");
scanf("%d%d",&a,&b);
printf("\n Before swap a = %d\t, b = %d",a,b);
a ^= b ^= a ^= b;
printf("\n\n After swap a = %d\t, b = %d",a,b);
getch();
}
OUTPUT:
Enter two number : 6 9
After swap a = 6 , b = 9
Before swap a = 9 , b = 6
After swap a = 6 , b = 9
Before swap a = 9 , b = 6
No comments:
Post a Comment