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

What are local variables c?

0 Answers  


In C programming, how do you insert quote characters (‘ and “) into the output screen?

0 Answers  


What are the advantages and disadvantages of c language?

0 Answers  


A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none

0 Answers  


Is the below things valid & where it will be stored in memory layout ? static const volatile int i; register struct { } ; static register;

2 Answers   Lucent,


Explain what are the __date__ and __time__ preprocessor commands?

0 Answers  


What is the exact difference between '\0' and ""

3 Answers  


in b=6.6/a+(2*a+(3*c)/a*d)/(2/n); which operation will be performed first a) 6.6/a b) 2*a c) 3*c d) 2/n

1 Answers  


where does malloc() function get the memory?

1 Answers  


what is recursion in C

0 Answers   Cap Gemini,


1) write a program to generate 1st n fibonacci prime numbers using Nested if 2) write a program to generate twin prime numbers from m to n using nested if 3) write a program to check whether a given integer is a strong number or not using nested if 4) Write a program to generate prime factors of a given integer using nested if 5)write a program to generate prime numbers from m to n using nested if 6)write a program to generate perfect numbers from m to n using nested if 7)write a program to generate the pallindromes from m to n using neste if 8)write a program to generate armstrong numbers from m to n using nested if 9)write a program to generate strong numbers from m to n using nested if

0 Answers   TCS,


How to print "Hi World" without using semi colon?

6 Answers   Infosys,


Categories