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() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }

2 Answers   IBM,


main( ) { void *vp; char ch = ‘g’, *cp = “goofy”; int j = 20; vp = &ch; printf(“%c”, *(char *)vp); vp = &j; printf(“%d”,*(int *)vp); vp = cp; printf(“%s”,(char *)vp + 3); }

1 Answers  


main() { int (*functable[2])(char *format, ...) ={printf, scanf}; int i = 100; (*functable[0])("%d", i); (*functable[1])("%d", i); (*functable[1])("%d", i); (*functable[0])("%d", &i); } a. 100, Runtime error. b. 100, Random number, Random number, Random number. c. Compile error d. 100, Random number

1 Answers   HCL, rsystems,


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

1 Answers  


String copy logic in one line.

11 Answers   Microsoft, NetApp,






Find the largest number in a binary tree

7 Answers   Infosys,


main() { extern out; printf("%d", out); } int out=100;

1 Answers  


#include"math.h" void main() { printf("Hi everybody"); } if <stdio.h> will be included then this program will must compile, but as we know that when we include a header file in "" then any system defined function find its defination from all the directrives. So is this code of segment will compile? If no then why?

2 Answers  


main() { struct date; struct student { char name[30]; struct date dob; }stud; struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }

1 Answers  


What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

1 Answers  


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

1 Answers  


main() { int i, j; scanf("%d %d"+scanf("%d %d", &i, &j)); printf("%d %d", i, j); } a. Runtime error. b. 0, 0 c. Compile error d. the first two values entered by the user

2 Answers   HCL,


Categories