Users Online
· Guests Online: 145
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
41 C Program to Swap the Contents of two Numbers using Bitwise XOR Operation
This C Program swaps the contents of two numbers using bitwise XOR operation.
Here is source code of the C program to swap the contents of two numbers using bitwise XOR operation. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* 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("\n Before swapping i= %ld and k = %ld", i, k);
i = i ^ k;
k = i ^ k;
i = i ^ k;
printf("\n After swapping i= %ld and k = %ld", i, k);
}
$ cc pgm48.c
$ a.out
Enter two integers
45
89
Before swapping i= 45 and k = 89
After swapping i= 89 and k = 45
Here is source code of the C program to swap the contents of two numbers using bitwise XOR operation. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* 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("\n Before swapping i= %ld and k = %ld", i, k);
i = i ^ k;
k = i ^ k;
i = i ^ k;
printf("\n After swapping i= %ld and k = %ld", i, k);
}
$ cc pgm48.c
$ a.out
Enter two integers
45
89
Before swapping i= 45 and k = 89
After swapping i= 89 and k = 45
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.