ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       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
Google
   
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther 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?
Answer
# 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?
Answer
# 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?
Answer
# 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
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
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. Tcs1
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 CSC8
which one is not preprocessor directive a)#if b)#elif c)#undef d)#pragma Wipro16
Program to find the absolute value of given integer using Conditional Operators N-Tech5
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 ? TCS2
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? Google6
out put of printf(“%d”,printf(ram));  5
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2012  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com