Tuesday, 17 May 2011

swapping two numbers without using third variable

#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6;
clrscr();
a^=b;
b^=a;
a^=b;
printf("a=%d b=%d",a,b);
getch();
}

(or)
 #include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6;
clrscr();
a=a+b;
b=a-b;
a=a-b;
printf("a=%d b=%d",a,b);
getch();
}


No comments:

Post a Comment