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

Why is c called a mid-level programming language?

737


What is the difference between new and malloc functions?

587


Explain the ternary tree?

613


What are preprocessor directives in c?

655


List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.

2313






Why double pointer is used in c?

577


What are the ways to a null pointer can use in c programming language?

600


Explain spaghetti programming?

691


What is volatile keyword in c?

589


What is a program?

675


Can you write the algorithm for Queue?

1561


When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd

651


What are the characteristics of arrays in c?

622


What are the advantages and disadvantages of c language?

571


How many types of sorting are there in c?

624