About 1,190,000 results
Open links in new tab
  1. C Program to Swapping Two Numbers Using Bitwise Operators

    This C program is used to swapping two numbers, using bitwise operators. Program: #include <stdio.h> int main() { int i = 65; int k = 120; printf(" value of i=%d k=%d before swapping", i, k); i = i ^ k; k = i ^ k; i = i ^ k; printf("value of i=%d k=%d after swapping", i, k); return 0; }

  2. Swapping Numbers Using Bitwise Operator in C - Online …

    Mar 5, 2021 · How to swap the numbers using the bitwise operator in the C programming language? The compiler swap the given numbers, first, it converts the given decimal number into binary equivalent then it performs a bitwise XOR operation to exchange the numbers from one memory location to another.

  3. C Program to Swap two Numbers using Bitwise Operators

    * C Program to Swap two Numbers using Bitwise operators */ #include <stdio.h> #include <string.h> /* Function Prototype */ void swap (int *, int *); void main {int num1, num2; printf (" \n Enter two numbers:"); scanf ("%d %d", & num1, & num2); printf (" \n The numbers before swapping are Number1= %d Number2 = %d", num1, num2);

  4. Swap Two Numbers Without Using Third Variable - GeeksforGeeks

    Dec 26, 2024 · // C# Code to swap two numbers using bitwise XOR using System; class GfG {static void Main {int a = 2, b = 3; Console. WriteLine ( "a = " + a + " b = " + b ); // Swap a and b using arithmetic operators a = a ^ b ; b = a ^ b ; a = a ^ b ; Console .

  5. C program to swap two numbers using bitwise operator

    Jan 27, 2016 · We can use bitwise XOR ^ operator to swap to numbers. Bitwise XOR operator evaluates each bit of the result to 1 if corresponding bits of the operands are different otherwise evaluates 0 . Suppose two integer values a and b

  6. C Program to Swap Two Numbers - GeeksforGeeks

    Jan 10, 2025 · // C Program to Swap Two Numbers using Bitwise // XOR Operator #include <stdio.h> int main {int a = 5, b = 10; // Apply XOR operations in the given order // to swap values a = a ^ b; b = a ^ b; a = a ^ b; printf ("a = %d, b = %d \n ", a, b); return 0;}

  7. C Program to swap two numbers - Aticleworld

    We will write the C program to swap two numbers using the Arithmetic Operators, Bitwise Operators. We will also create a function two swap two numbers using call by reference. What is swapping mean?

  8. C Program to Swap Two Numbers without using Temporary …

    In this C program, we are reading two integers using ‘i’ and ’k’ integer variables respectively. To swap the integer values without using a temporary variable or arithmetic operators. The bitwise XOR operator is used to copy the bit if it is set in one operand but not both. Print the swapped values of numbers.

  9. C program to swap two Integers using Bitwise Operators

    Jan 6, 2019 · Write a C program to swap two integers using bitwise operators without using any temporary variable. Let n1 and n2 be two numbers to be swapped. Update n2 to n1^n2, i.e., n2=n1^n2 // n1 is already updated in previous step, use the updated value. Again update n1 to n1^n2, i.e., n1=n1^n2 // n2 already updated in previous step.

  10. C Program to Swapping Two Numbers Using Bitwise Operators

    This C program is used to swapping two numbers, using bitwise operators. Program: #include <stdio.h> int main() { int i = 65; int k = 120; printf(" value of i=%d k=%d before swapping", i, k); i = i ^ k; k = i ^ k; i = i ^ k; printf("value of i=%d k=%d after swapping", i, k); return 0;} Explanation:

Refresh