How to swap 3 numbers without using 4th variable?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between the = symbol and == symbol?

617


When should we use pointers in a c program?

618


Explain enumerated types.

592


What is the sizeof () operator?

612


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3107






How can I ensure that integer arithmetic doesnt overflow?

600


Why c language is called c?

560


Explain the use of 'auto' keyword in c programming?

670


find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }

1855


Explain modulus operator.

588


Why clrscr is used in c?

573


Why do we use int main instead of void main in c?

606


What is a structure and why it is used?

613


What is keyword in c?

591


Why can't I perform arithmetic on a void* pointer?

630