Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
 Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE

 Categories  >>  Software  >>  Programming Languages  >>  C

 C Interview Questions C++ Interview Questions VC++ Interview Questions Delphi Interview Questions Programming Languages AllOther Interview Questions
Question
```write a program to swap two numbers without using temporary
variable?```
Question Submitted By :: Vatsava
I also faced this Question!!     Rank Answer Posted By

Re: write a program to swap two numbers without using temporary variable?
# 1
let a and b be the variables

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

if we take a=5 and b = 7 then

a = 5+7 = 12
b = 12-7 = 5
a = 12-5 = 7

hence swaped...

 Is This Answer Correct ? 25 Yes 3 No
It Diploma Student

Re: write a program to swap two numbers without using temporary variable?
# 2
[code]

main()
{
int a=10;
int b=20;
printf("a = %d\nb = %d\n",a,b);
a =a+b; b=a-b; a=a-b; // This is first way.

a =a*b; b=a/b; a=a/b;
printf("a = %d\nb = %d\n",a,b);
}
[/code]

[code]
main()
{
int a=10;
int b=20;
printf("a = %d\nb = %d\n",a,b);
a =a*b; b=a/b; a=a/b; //This is second way
printf("a = %d\nb = %d\n",a,b);
}
[/code]

 Is This Answer Correct ? 18 Yes 2 No
Guest

Re: write a program to swap two numbers without using temporary variable?
# 3
let a and b be variables
a^=b^=a^=b;
by performing this logic from right hand side we can swap
two variables

 Is This Answer Correct ? 6 Yes 4 No
Sam

  Question Asked @ Answers Other C Interview Questions while running a program, i got the msg that press return key to exit.what that mean in C as there are no such options as far i know. Tcs 1 Without using main fn and semicolon,print remainder for a given number in C language 1 write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 CSC 8 which one is not preprocessor directive a)#if b)#elif c)#undef d)#pragma Wipro 16 Program to find the absolute value of given integer using Conditional Operators N-Tech 5 write a program for fibonaci series by using while loop in c? 2 where can function pointers be used? 2 Write a C program to check a number even or odd, without using any relational, arithmetic operator and any loops. 1 how does a general function , that accepts an array as a parameter, "knows" the size of the array ? How should it define it parameters list ? TCS 2 simple program for virtual function? 1 value = 0xabcd; for (loop = 1; (value >> 1) & 1 | loop & 1; loop++) { foo(); if (loop & 1) value >>= 1; } how many times is foo() executed? Google 6 out put of printf(“%d”,printf(ram)); 5 For more C Interview Questions Click Here