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

main() { char a[4]="HELLO"; printf("%s",a); }

3 Answers   CSC,


how to delete an element in an array

2 Answers   IBM,


main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }

1 Answers  


main() { static int var = 5; printf("%d ",var--); if(var) main(); }

1 Answers  


Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

0 Answers   IBM,






main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n %u %u ",j,k); }

1 Answers  


main() { char *p; p="%d\n"; p++; p++; printf(p-2,300); }

1 Answers  


main() { printf("%d, %d", sizeof('c'), sizeof(100)); } a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4

18 Answers   HCL, IBM, Infosys, LG Soft, Satyam,


main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error

1 Answers   HCL,


{ int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

4 Answers  


How to reverse a String without using C functions ?

33 Answers   Matrix, TCS, Wipro,


Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like.

21 Answers   ABC, eBay, Goldman Sachs, Google, HUP, Microsoft, TATA,


Categories