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

What does emoji p mean?

794


Explain what are multibyte characters?

868


What is the advantage of an array over individual variables?

987


What is chain pointer in c?

781


A routine usually part of the operation system that loads a program into memory prior to execution a) linker b) loader c) preprocessor d) compiler

864


Can you define which header file to include at compile time?

800


Why is extern used in c?

834


How to find a missed value, if you want to store 100 values in a 99 sized array?

1088


What is #line?

822


What is the translation phases used in c language?

835


to find the closest pair

2060


What are the different types of constants?

841


How are portions of a program disabled in demo versions?

1012


What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25

1707


What is header file definition?

819