How many ways are there to swap two numbers without using
temporary variable? Give the each logic.

Answer Posted / alok bajpai

You can swap two Numbers without using temporary variable
with the help of EX-OR operator;

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the first No.:");
scanf("%d",&a);
printf("Enter the second No.:");
scanf("%d",&b);
a^=b^=a^=b;
printf("%d %d",a,b);
getch();
}

Is This Answer Correct ?    19 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between strcpy() and memcpy() function?

800


Does c have circular shift operators?

985


a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none

990


What is equivalent to ++i+++j?

879


differentiate built-in functions and user – defined functions.

888


Explain bit masking in c?

933


1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. The Logic should be written in Data Structures?

2210


Why c is called object oriented language?

839


How will you print TATA alone from TATA POWER using string copy and concate commands in C?

1187


Where does the name "C" come from, anyway?

894


An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above

948


swap 2 numbers without using third variable?

906


What is c value paradox explain?

814


Tell us the use of fflush() function in c language?

915


What are the characteristics of arrays in c?

843