How to swap 3 numbers without using 4th variable?

Answers were Sorted based on User's Feedback



How to swap 3 numbers without using 4th variable?..

Answer / sundar

a=a+b+c
b=a-(b+c)
c=a-(b+c)
a=a-(b+c)

Is This Answer Correct ?    89 Yes 13 No

How to swap 3 numbers without using 4th variable?..

Answer / pallavi dhanopiya

a=a*b*c;
b=a/b/c;
c=a/b/c;
a=a/b/c;

Is This Answer Correct ?    12 Yes 3 No

How to swap 3 numbers without using 4th variable?..

Answer / ilana

The target is a<-b b<-c c<- a
------------------------------------
a = a+b+c ; // a+b+c b c
c = c+b; // a+b+c b b+c
b = c-b; // a+b+c c b+c
c = a-c; // a+b+c c a
a = a-(b+c) // b c a

Is This Answer Correct ?    12 Yes 7 No

How to swap 3 numbers without using 4th variable?..

Answer / mujamil

how to swap of 4number

Is This Answer Correct ?    3 Yes 1 No

How to swap 3 numbers without using 4th variable?..

Answer / pavan

a=(a+b+c)-(b=a)-(c=b)

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More C Interview Questions

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

0 Answers   Ignou,


Suppose I want to write a function that takes a generic pointer as an argument and I want to simulate passing it by reference. Can I give the formal parameter type void **, and do something like this? void f(void **); double *dp; f((void **)&dp);

1 Answers  


Write program to remove duplicate in an array?

0 Answers  


how write a addtion of two single dimensional array using of pointer in c language?

3 Answers   DRDO,


What is the mean of this statement:: if(int i=0 * i=9)

2 Answers   HCL,


If fflush wont work, what can I use to flush input?

0 Answers  


Write a C Programm.. we press 'a' , it shows the albhabetical number is 1, if we press 'g' it shows the answer 7.. any can help me

7 Answers  


Explain what is dynamic data structure?

0 Answers  


what is the use of #pragma pack, wer it is used?

2 Answers   Wipro,


Explain what happens if you free a pointer twice?

0 Answers  


what is pointer ?

10 Answers   Kernex Micro Systems,


Is array a primitive data type in c?

0 Answers  


Categories