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

struct Foo { char *pName; char *pAddress; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); obj->pName = malloc(100); obj->pAddress = malloc(100); strcpy(obj->pName,"Your Name"); strcpy(obj->pAddress, "Your Address"); free(obj); printf("%s", obj->pName); printf("%s", obj->pAddress); } a. Your Name, Your Address b. Your Address, Your Address c. Your Name Your Name d. None of the above

2 Answers   HCL,


write a c program to Create a mail account by taking the username, password, confirm password, secret_question, secret_answer and phone number. Allow users to register, login and reset password(based on secret question). Display the user accounts and their details .

2 Answers  


How we print the table of 3 using for loop in c programing?

7 Answers  


There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong? void main() { struct student { char name[30], rollno[6]; }stud; FILE *fp = fopen(“somefile.dat”,”r”); while(!feof(fp)) { fread(&stud, sizeof(stud), 1 , fp); puts(stud.name); } }

1 Answers  


Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution)

7 Answers   Microsoft,






main() { printf("%x",-1<<4); }

3 Answers   HCL, Sokrati, Zoho,


struct Foo { char *pName; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); strcpy(obj->pName,"Your Name"); printf("%s", obj->pName); } a. Your Name b. compile error c. Name d. Runtime error

3 Answers   HCL,


Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };

1 Answers  


How will u find whether a linked list has a loop or not?

8 Answers   Microsoft,


const int perplexed = 2; #define perplexed 3 main() { #ifdef perplexed #undef perplexed #define perplexed 4 #endif printf("%d",perplexed); } a. 0 b. 2 c. 4 d. none of the above

1 Answers   emc2, HCL,


Is this code legal? int *ptr; ptr = (int *) 0x400;

1 Answers  


C statement to copy a string without using loop and library function..

2 Answers   Persistent, TCS,


Categories