c program to swap the contents of two numbers using bit-wise XOR operation. Don’t use either the temporary variable or arithmetic operators

by Nideesh C on April 12, 2011 · 0 comments

in C Programming




/* c program to swap the contents of two numbers using bit-wise 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
——————————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to read two integers M and N and to swap their values. Use a user-defined function for swapping. Output the values of M and N before and after swapping with suitable messages
  2. C program to find the number of integers divisible by 5 between the given range N1 and N2, where N1 < N2 and are integers. Also find the sum of all these integer numbers that divisible by 5 and output the computed results
  3. C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
  4. C program to simulate a simple calculator to perform arithmetic operations like addition, subtraction,multiplication and division only on integers
  5. C program to read in four integer numbers into an array and find the average of largest two of the given numbers without sorting the array. The program should output the given four numbers and the average with suitable headings.

Leave a Comment

Previous post:

Next post: