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                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
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 interchange two variables without using 
the third variable?
 Question Submitted By :: Rajesh
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 1
#include<stdio.h>
void main()
{
 int x,y;
 printf("enter x and y");
 scanf("%d%d",&x,&y);
 x=x+y;
 y=x-y;
 x=x-y;
 printf("elements after swapping :%d,%d",x,y);
}
 
Is This Answer Correct ?    48 Yes 6 No
Guest
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 2
#include<stdio.h>
void main()
{
  int x,y;
  printf("enter x and y: ");
  scanf("%d%d",&x,&y);
  x^=y;
  y^=x;
  x^=y;
  printf("elements after swapping: %d,%d\n",x,y);
}
 
Is This Answer Correct ?    6 Yes 10 No
Tom Macdonald
 
 
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 3
#include<stdio.h>
void main()
{
  int x,y;
  printf("enter x and y: ");
  scanf("%d%d",&x,&y);
  x^=y^=x^=y;   
   printf("elements after swapping: %d,%d\n",x,y);
}
 
Is This Answer Correct ?    7 Yes 6 No
Satish
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 4
#include<stdio.h>
#include<conio.h>
void main()
  {
int a,b,c;
clrscr();
printf("Enter two no");
scanf("%d%d",&a,&b);
c=a+b;
b=a-b;
a=a-b;
printf("After chanching no is =\n");
printf("a=%d   b=%d",a,b);
getch();
}
 
Is This Answer Correct ?    10 Yes 5 No
Mahendra Giri
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 5
void main()
{
int a,b;
printf("enter two no ");
scanf("%d%d",&a,&b);
printf("a=%d and b=%d",a,b);
a=a^b;
b=a^b;
a=a^b;
printf("a=%d and b=%d",a,b);
getch();
}
 
Is This Answer Correct ?    5 Yes 2 No
Vinay Tiwari
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 6
you can apply it on any language?!

x = x xor y
y = x xor y
x = x xor y

    * 1 year ago

Source(s):
Self Expierince
 
Is This Answer Correct ?    2 Yes 3 No
Saravanan J (srm Universi
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 7
#include<stdio.h>
#include<conio.h>
void main()
  {
int a,b,c;
clrscr();
printf("Enter two no");
scanf("%d%d",&a,&b);
c=a*b;
b=a/b;
a=b/a;
printf("After chanching no is =\n");
printf("a=%d   b=%d",a,b);
getch();
}
 
Is This Answer Correct ?    7 Yes 6 No
Deepa.n
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 8
#include<stdio.h>
#include<conio.h>
void main()
  {
int a,b;
clrscr();
printf("Enter two no");
scanf("%d%d",&a,&b);
a=a-b;
b=a+b;
a=b-a;
printf("After chanching no is =\n");
printf("a=%d   b=%d",a,b);
getch();
}
 
Is This Answer Correct ?    7 Yes 1 No
Jisha. K.a
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 9
#include<stdio.h>
#include<conio.h>
void main()
  {
int a,b;
clrscr();
printf("Enter two no");
scanf("%d%d",&a,&b);
a=a*b;
b=a/b;
a=b/a;
printf("After chanching no is =\n");
printf("a=%d   b=%d",a,b);
getch();
}
 
Is This Answer Correct ?    3 Yes 5 No
Deepa.n
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 10
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the value of A and B");
scanf("%d %d",&a,&b);
b=(a+b-a=b);
printf("After interchange value are %d %d",a,b);
getch();
}
 
Is This Answer Correct ?    2 Yes 4 No
Debasis Nayak
 
  Re: Write a program to interchange two variables without using the third variable?
Answer
# 11
#include<stdio.h>
#include<conio.h>
void main()
  {
int a,b;
clrscr();
printf("Enter two no");
scanf("%d%d",&a,&b);
a=a*b;
b=a/b;
a=a/b;
printf("After chanching no is =\n");
printf("a=%d   b=%d",a,b);
getch();
}
 
Is This Answer Correct ?    4 Yes 1 No
Raghavendra
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
whether itis a structured language? Microsoft1
what is a c-language.what is do. HCL3
main() { printf("hello%d",print("QUARK test?")); }  4
C,c++, Java is all are structural oriented or procedure oriented language..?  3
how can i get output like this? 1 2 3 4 5 6 Excel3
what is meant by the "equivalence of pointers and arrays" in C? Satyam3
wats the diference btwen constant pointer and pointer to a constant.pls give examples.  6
which type of question asked from c / c++ in interview.  2
I have a function which accepts a pointer to an int. How can I pass a constant like 5 to it?  3
what is differnence b/w macro & functions  1
Print all the palindrome numbers.If a number is not palindrome make it one by attaching the reverse to it. eg:123 output:123321 (or) 12321  2
which operator having highest precedence? a.)+ b.)++ c.)= d.)%  3
Given an array of characters, how would you reverse it? How would you reverse it without using indexing in the array?  1
True or false: If you continuously increment a variable, it will become negative? 1) True 2) False 3) It depends on the variable type  5
what is call by value and call by reference  2
related to rdbms query .  1
int a=1,b=2,c=3; printf("%d,%d",a,b,c); What is the output? Verifone14
#define MAX(x,y) (x) > (y) ? (x) : (y) main() { int i = 10, j = 5, k = 0; k = MAX(i++, ++j); printf("%d %d %d", i,j,k); } what will the values of i , j and k? } NDS9
What is the difference between static and global variables?  1
how many keywords do C compile? Microsoft2
 
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