Delicious Digg Facebook Favorites More Stumbleupon Twitter

Tuesday 4 September 2012

swapped 2 numbers without using 3 variable


       Swapped 2 numbers without using 3 variable

       #include<stdio.h>
       main()
       {
             int a=10,b=20;
             printf("\noriginal values of a=%d,b=%d",a,b);
             a=a^b;
             b=a^b;
             a=a^b;
             printf("\nswapped values of a=%d,b=%d",a,b);
             getch();
       }
     
       output :-

                 original values of a=10,b=20
                 swapped values of a=20,b=10

                 



0 comments:

Post a Comment