C PROGRAM TO SWAP TWO NUMBERS | Indian Shout

You are here: » C PROGRAM TO SWAP TWO NUMBERS

C PROGRAM TO SWAP TWO NUMBERS

/*    Write a c program to swap the contents of two numbers using bitwise XOR operation. Don’t use either the temporary variable or arithmetic operators  */

 #include <stdio.h>
 void main()
 {
long i,k;
printf(“Enter two integers\n”);
scanf(“%ld %ld”,&i,&k);
printf(“\nBefore swapping i= %ld and k = %ld”,i,k);
i = i^k;
k = i^k;
i = i^k;
printf(“\nAfter swapping i= %ld and k = %ld”,i,k);
 }
/*——————————————
Output
Enter two integers
23 34
Before swapping i= 23 and k = 34
After swapping i= 34 and k = 23
——————————————*/


ilook website
 
 

Categories:Uncategorized;Tags: , , , , , , ,

   

One Comment to “C PROGRAM TO SWAP TWO NUMBERS”

  1. harshad says:

    very nice.good

Leave your comment here: