Swapping Of Two Numbers In C Without Temporary Variable

[Solved] Swapping Of Two Numbers In C Without Temporary Variable | C - Code Explorer | yomemimo.com
Question : swapping of two numbers in c without temporary variable

Answered by : healthy-hare-aoylwn8hvx1u

#include<stdio.h>
void main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swap a=%d b=%d",a,b);
} 

Source : | Last Update : Tue, 12 Apr 22

Question : c program for swapping of two numbers using temporary variable

Answered by : vincent-otieno

#include <stdio.h>
int main()
{ int a, b, temp; printf("enter the values of a and b: \n"); scanf("%d%d", &a, &b ); printf("current values are:\n a=%d\n b=%d\n", a, b); temp=a; a=b; b=temp; printf("After swapping:\n a=%d\n b=%d\n", a, b);
}

Source : | Last Update : Mon, 26 Apr 21

Question : swapping two numbers in c

Answered by : sub0d00

//Author: Subodh //! Swap two number using XOR operation cout << "Before, n1 = " << num1 << ", n2 = " << num2 << endl; num1 = num1 ^ num2, num2 = num1 ^ num2, num1 = num1 ^ num2; cout << "After, n1 = " << num1 << ", n2 = " << num2 << endl;

Source : | Last Update : Fri, 05 Aug 22

Question : c program for swapping of two numbers

Answered by : weary-wolf-fzundl3ii92g

// Overcomplicating things lol. Try this
#include <stdio.h>
int main()
{ int x, y; printf("Enter Value of x "); scanf("%d", &x); printf("\nEnter Value of y "); scanf("%d", &y); int temp = x; x = y; y = temp; printf("\nAfter Swapping: x = %d, y = %d", x, y); return 0;
}

Source : | Last Update : Sun, 13 Mar 22

Question : swapping of two numbers without using third variable in c

Answered by : mridul-ghosh

#include<stdio.h>
void main()
{	int x = 10, y = 20; printf("Before swap x=%d y=%d",x,y); x=x+y; y=x-y; x=x-y; printf("\nAfter swap x=%d y=%d",x,y);
}

Source : | Last Update : Mon, 02 May 22

Answers related to swapping of two numbers in c without temporary variable

Code Explorer Popular Question For C