how to swap 3 nos without using temporary variable

Answers were Sorted based on User's Feedback



how to swap 3 nos without using temporary variable..

Answer / prashant bhanushali

a = a + b
b = a - b
a = a - b

Is This Answer Correct ?    11 Yes 2 No

how to swap 3 nos without using temporary variable..

Answer / ganesh

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

Is This Answer Correct ?    8 Yes 0 No

how to swap 3 nos without using temporary variable..

Answer / vivek

<?php
$a=10;
$b=20;
$c=30;


list($b,$c,$a) = array($a,$b,$c);

echo $a;
echo $b;
echo $c;


$a = $a ^ $b;
$b = $a ^ $b;
$a = $a ^ $b;
echo $a . $b;
?>

Is This Answer Correct ?    3 Yes 2 No

how to swap 3 nos without using temporary variable..

Answer / saurabh sinha

a=a^b;
b=b^a;
a=a^b;

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Code Interview Questions

# include<stdio.h> aaa() { printf("hi"); } bbb(){ printf("hello"); } ccc(){ printf("bye"); } main() { int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2](); }

1 Answers  


How to count a sum, when the numbers are read from stdin and stored into a structure?

1 Answers  


how can u draw a rectangle in C

53 Answers   Accenture, CO, Codeblocks, Cognizant, HCL, Oracle, Punjab National Bank, SAP Labs, TCS, University, Wipro,


how to check whether a linked list is circular.

11 Answers   Microsoft,


main() { float me = 1.1; double you = 1.1; if(me==you) printf("I love U"); else printf("I hate U"); }

1 Answers  


void main() { void *v; int integer=2; int *i=&integer; v=i; printf("%d",(int*)*v); }

1 Answers   Honeywell,


main() { unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

1 Answers  


write a program for area of circumference of shapes

0 Answers  


main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }

3 Answers  


main() { signed int bit=512, mBit; { mBit = ~bit; bit = bit & ~bit ; printf("%d %d", bit, mBit); } } a. 0, 0 b. 0, 513 c. 512, 0 d. 0, -513

3 Answers   HCL, Logical Computers,


#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x); printf("%s",s->name); }

1 Answers   TCS,


To reverse an entire text file into another text file.... get d file names in cmd line

0 Answers   Subex,


Categories