answersLogoWhite

0


Best Answer

To swap two numbers N1 and N2, using a third variable T... T = N1;

N1 = N2;

N2 = T;

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Swapping of number with using third variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is program in c to swap entered two numbers without using third variable?

The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include<stdio.h> main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&a); printf("Enter b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }


How do you find the greatest of three numbers using ternery operator?

Compare the first two numbers with the ternary operator. Store the result in a temporary variable. Compare the temporary variable with the third number, again using the ternary operator.


Swap logic without using third variable?

a ^= b; b ^= a; a ^= b;


How do you swap in c programming?

the simple way can be explained by example as: let there be two integers as : int a=10,b=5; if we want to use third variable then let third variable be int c; and sorting is done as : c=a; a=b; b=c; if it is to be done by without using third variable then : a=a+b; b=a-b; a=a-b; at last the variable is sorted.


Write C coding for swamping the values of two variables without using a third variable?

I'll assume you meant to say: Swapping instead of Swamping. You would need to perform the XorSwap algorithm: void XorSwap(int *x, int *y) { if(x != y) { *x ^= *y; *y ^= *x; *x ^= *y; } } You can read more about this algorithm on Wikipedia.

Related questions

What is program in c to swap entered two numbers without using third variable?

The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include<stdio.h> main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&a); printf("Enter b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }


Swapping without third variable?

There are two ways in which you can swap without a third variable. 1. Using xor operation swap( int *a, int *b) { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; } 2. Using addition and subtraction swap( int *a, int *b) { *a = *a + *b; *b = *a - *b; *a = *a - *b; } }


What is the advantage of swapping two variables without using 3 variable?

Nothing. Never do that.


How do you find the greatest of three numbers using ternery operator?

Compare the first two numbers with the ternary operator. Store the result in a temporary variable. Compare the temporary variable with the third number, again using the ternary operator.


Swap logic without using third variable?

a ^= b; b ^= a; a ^= b;


What is the Concept of swapping with only two variable?

Non-using of temporal variable. It is possible, but has no use in real programming. Eg. a := a XOR b b := a XOR b a := a XOR b I warn you again: this is just a curiosity, not something you really use.


How do you swap variables in PHP?

By using a third temporary variable. $tmp = $a; $a = $b; $b = $tmp;


With one variable swap the number using c language?

includeincludemain(){int a,b;clrscr();printf("enter the value of a & b\n");scanf("%d%d,&a,&b");a=a+b;b=a-b;a=a-b;printf(" value of a is %d & b is %d after swapping");getch();}


How do you swap in c programming?

the simple way can be explained by example as: let there be two integers as : int a=10,b=5; if we want to use third variable then let third variable be int c; and sorting is done as : c=a; a=b; b=c; if it is to be done by without using third variable then : a=a+b; b=a-b; a=a-b; at last the variable is sorted.


When 16 is divided by a number using x as the variable the result is 3?

5.3333


Swapping of two variables withou using temp variable?

example: x = x-y; y = y-x; x = y-x; <><><> It is not possible to swap two variables without using a temp variable. The code in the answer above, while clever, does not swap the variables. It will exchange the variable values for certain values of x and y, e.g. when x and y are small integers. If x and y are other values, such as strings, pointers, Infinity, NaN (not a number), floating point, or near the limits of the representation (causing over/underflow) then the code will not "swap" the values. <---> Note: there is absolutely no point in swapping two variables without using temopral variable, it's just a typical homework question, already asked here countless times. Another variation: a ^= b; b ^= a; a ^= b;


How do you write as a variable expression two-fifths of a number using n as the variable?

2n/5 or (2/5)*n