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                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2266)
 C++ interview questions  C++ Interview Questions (1121)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (652)
Question
write a program to swap Two numbers without using temp variable.
 Question Submitted By :: C
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
a=a+b;
b=a-b;
a=a-b;
 
Is This Answer Correct ?    1381 Yes 156 No
Chandan
 
Answer
# 2
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("\n Enter the 2 numbers");
scanf("%d%d",&a,&b);
//swaping of 2 numbers without using temp variable
a=a+b;
b=a-b;
a=a-b;
/* or
a=a*b;
b=a/b;
a=a/b;
*/
printf("\n A = %d \n B = %d\n");
getch();
}
 
Is This Answer Correct ?    588 Yes 119 No
Harisharumalla
 
 
 
Answer
# 3
void swap(int *a,int *b)
{
if(*a == *b)
return;
*a^=*b;
*b^=*a;
*a^=*b;
}
 
Is This Answer Correct ?    458 Yes 195 No
Abhi
 
Answer
# 4
Swapping two variables in a single line with no temporary
variable..

b=(a+b)-(a=b);

so.. simple..

Prasanna. (prasanna7287@yahoo.co.in)
 
Is This Answer Correct ?    347 Yes 137 No
Prasanna
 
Answer
# 5
# include "stdio.h"
main()
{
int a,b;
printf("enter two numbers for swaping");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("a is %d",a);
printf("b is %d",b);
} output:- takea,b value is 2,3 and give answers is3,2
 
Is This Answer Correct ?    239 Yes 56 No
Guest
 
Answer
# 6
b=a+b
a=b-a
b=b-a

if a=3 and b=5
then now b=a+b=8
and a=8-a=8-3=5,now a=5
b=8-a=8-5=3,now b=3

so, a=5 and b=3
 
Is This Answer Correct ?    197 Yes 58 No
Anantha
 
Answer
# 7
a=a+b;
b=a-b;
a=a-b;
printf("a %dand b %dis :",a,b);
 
Is This Answer Correct ?    181 Yes 42 No
Nagakishorebabu
 
Answer
# 8
void main()
{
int a,b;
printf("enter the two numbers");
scanf("%d%d",&a,&b);
a^=b^=a^=b;
printf("%d%d",a,b);//swapped no
}
 
Is This Answer Correct ?    118 Yes 66 No
Ravi Saini
 
Answer
# 9
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("Enter two numbers");
scanf("%d %d",&a &b);
a=a+b;
b=a-b;
a=a-b;
printf("The swapped values are:");
printf("a:%d",a);
printf("b:%d",b);
getch();
}
 
Is This Answer Correct ?    73 Yes 23 No
Sree
 
Answer
# 10
main()
{
int a=2,b=3;
a=a+b;
b=a-b;
a=a-b;
printf("%d",&a);
printf("%d",&b);
getch();
}
 
Is This Answer Correct ?    72 Yes 26 No
Sweety
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
write a c program for print your name .but,your name may be small letter mean print a capital letter or your name may be capital letter mean print a small letter .example \\enter ur name : sankar The name is: SANKAR (or) enter your name:SAnkar The name is:saNKAR IBM 3
What is Lazy evaluation in C? Give an example.   1
what is the difference between call by value and call by reference? Infosys 5
1.)how to find d most repeated word in a string? string ="how do you do"?? output should be do Nagarro 1
what is the differnce between AF_INET and PF_INET? Wipro 4
i want to make a program in which we use input having four digits(4321) and get output its reciprocal(1234).   1
What is the output of the below program and how it is? void main() { static int var=5; printf("%d",var--); if(var) main(); } Tech-Mahindra 6
plz answer....A program that takes 3 variables e.g a,b,c in as seperate parameters and rotates the values stored so that value goes a to b, b to c and c to a .   3
What is the output of the following program main();{printf ("chennai""superkings"}; a. Chennai b. superkings c. error d. Chennai superkings   6
Write a program to remove the C comments(/* */) and C++ comments(//) from a file. The file should be declared in command line. Subex 3
write a program which will count occurance of a day between two dates. IonIdea 1
There are 3 baskets of fruits with worng lables,one basket has apple,another basket has orange,another has combination of apple and orange,what is the least way of interchange the lables. Google 14
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com