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

Print an integer using only putchar. Try doing it without using extra storage.

2 Answers  


how to swap 3 nos without using temporary variable

4 Answers   Satyam,


main() { static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]); }

2 Answers  


Write a procedure to implement highlight as a blinking operation

2 Answers  


Code for 1>"ascii to string" 2>"string to ascii"

1 Answers   Aricent, Global Logic,






main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }

1 Answers  


# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }

1 Answers  


3) Int Matrix of certain size was given, We had few valu= es in it like this. =97=97=97=97=97=97=97=97=97=97=97 1 = | 4 | | 5 | &= nbsp; | 45 =97=97=97=97=97=97=97=97=97=97=97 &n= bsp; | 3 | 3 | 5 | = | 4 =97=97=97=97=97=97=97=97=97=97=97 34 |&nbs= p; 3 | 3 | | 12 | &= nbsp; =97=97=97=97=97=97=97=97=97=97=97 3 | &nbs= p; | 3 | 4 | = | 3 =97=97=97=97=97=97=97=97=97=97=97 3 | = ; | | | = ; 3 | =97=97=97=97=97=97=97=97=97=97=97 &= nbsp; | | 4 | = ; | 4 | 3 We w= ere supposed to move back all the spaces in it at the end. Note: = If implemented this prog using recursion, would get higher preference.

0 Answers   RoboSoft,


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

1 Answers  


what is the code of the output of print the 10 fibonacci number series

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  


How do you write a program which produces its own source code as its output?

7 Answers  


Categories