ALLInterview.com :: Home Page KalAajKal.com
 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
How many ways are there to swap two numbers without using
temporary variable? Give the each logic.
 Question Submitted By :: Sivavendra
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How many ways are there to swap two numbers without using temporary variable? Give the each logic.
Answer
# 1
as for i know their are two different logics for the 
swapping techinque.... swapping is a type of techinque used 
for interchanging the two varibles in the operating 
memory....
1) using only variables
2) using EX-OR operator '^' 
first logic only know.
 void main()
{
int a,b;
printf("enter the a&b");
scanf("%d%d",&a,&b);
a+=b;
b=a-b;
a-=b;
printf("a=%d\nb=%d",a,b);
getch();
}
 
Is This Answer Correct ?    13 Yes 1 No
Vignesh1988i
 
  Re: How many ways are there to swap two numbers without using temporary variable? Give the each logic.
Answer
# 2
One more method its bit complicated from the people from 
the non electronics background......
void main()
{
   pf(" a and b ");
   sf("%d %d", &a, &b);
   a= a^b;
   b= b^a;
   a= a^b;
   pf("Swapped no's are a=%d and b=%d" ,a ,b);
}
 
Is This Answer Correct ?    6 Yes 1 No
Kishan Gowda
 
 
 
  Re: How many ways are there to swap two numbers without using temporary variable? Give the each logic.
Answer
# 3
You can swap two Numbers without using temporary variable 
with the help of EX-OR operator;

#include<stdio.h>
#include<conio.h>
void main()
{
 int a,b;
 clrscr(); 
 printf("Enter the first No.:");
 scanf("%d",&a);
 printf("Enter the second No.:");
 scanf("%d",&b);
 a^=b^=a^=b;
 printf("%d %d",a,b);
 getch();
}
 
Is This Answer Correct ?    5 Yes 1 No
Alok Bajpai
 
  Re: How many ways are there to swap two numbers without using temporary variable? Give the each logic.
Answer
# 4
as far i know i know two logics they are
first one
void main()
{
int a,b;
printf("eneter any two values");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("a=%d\nb=%d",a,b);
getch():
}
second one 
void main()
{
int a,b;
printf("eneter any two values");
scanf("%d%d",&a,&b);
a=a*b;
b=a/b;
a=a/b;
printf("a=%d\nb=%d",a,b);
getch():
}
 
Is This Answer Correct ?    6 Yes 0 No
Venkatesh Sabinkar
 
  Re: How many ways are there to swap two numbers without using temporary variable? Give the each logic.
Answer
# 5
three logic
xor -> a^=b^=a^=b;
addition and subtraction,
multiply and division .......
 
Is This Answer Correct ?    1 Yes 1 No
Kk
 
  Re: How many ways are there to swap two numbers without using temporary variable? Give the each logic.
Answer
# 6
in 7 types
 
Is This Answer Correct ?    0 Yes 2 No
Megha
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
How can I access memory located at a certain address?  2
study the code: #include<stdio.h> void main() { const int a=100; int *p; p=&a; (*p)++; printf("a=%dn(*p)=%dn",a,*p); } What is printed? A)100,101 B)100,100 C)101,101 D)None of the above Accenture13
Find string palindrome 10marks Honeywell5
how memory store byte Huawei3
Is there any restriction in how many arguments printf or scanf function can take? in which file in my c++ compiler i can see the code for implementation of these two functions??  3
difference between semaphores and mutex?  1
Switch (i) i=1; case 1 i++; case 2 ++i; break; case 3 --i; Output of i after executing the program Mascot4
writw a program to insert an element in the begning of a doubly linked list  1
what are the difference between ANSI C and Let Us c and Turbo C LG-Soft1
why TCS selected more student in the software field from all institution. TCS3
we all know about the function overloading concept used in C++ and we all learnt abt that.... but that concept is already came in C in a very smaller propotion ... my question is IN WHICH CONCEPT THERE IS A USE OF FUNCTION OVERLOADING IS USED in C language????????????? Google2
User define function contain thier own address or not.  2
1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collision Qualcomm6
write a fuction for accepting and replacing lowercase letter to'Z' with out using inline function. Temenos4
Print the foll in C...eg when n=5 the o/p must b + + + + + + + + + + + + + + + + +  1
consider the following program sigment int n,sum=1; switch(n) { case 2:sum=sum+2; case 3:sum*=2; break; default:sum=0;} if n=2, what is the value of sum a.0 b.6 c.3 d.none TCS4
what's the o/p int main(int n, char *argv[]) { char *s= *++argv; puts(s); exit(0); } Motorola1
which of the function operator cannot be over loaded a) <= b)?: c)== d)* HCL7
difference between i++* and *++i IBM3
If we give two names then this displays the connection between the two people. It is nothing but flames game  1
 
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 © 2007  ALLInterview.com.  All Rights Reserved.

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