Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


write a program to swap Two numbers without using temp variable.

Answers were Sorted based on User's Feedback



write a program to swap Two numbers without using temp variable...

Answer / joshin

main()
{
printf("enter two number");
scanf("%d%d",&a,&b);
printf("swaped result is b=%d\na=%d",b,a);
}

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / nikhil godani

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

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / amit chauhan

#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 ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / school

public class hack
{
magic printwall(the web must block);

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / harika

main()
{
int a=2,b=3;
a^=b^=a^=b;
printf("%d,%d",a,b);
}

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / saurav raj

#include<stdio.h>
#include<conio.h>

void main()
int a,b;
clrscr();
printf("Enter Two number a & b:- ");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("\nA=%d \t B=%d",a,b);
getch();

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / swechha

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

if a=5 and b=10 then
a=5-10=(-5)
b=(-5)+10=5
a=5-(-5)=5+5=10

now a=10 & b=5

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / prashant

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

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / ajith c.k

#include"stdio.h"
int swap(int *,int*);
int main()
{
int a,b;
printf("enter two number");
scanf("%d%d",&a,&b);
swap(&a,&b);
printf("%d\t%d",a,b);
return ;
}
int swap(int *s,int *q)
{

if(*s==*q)
return;
*s^=*q;
*q^=*s;
*s^=*q;
return ;
}

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / sur!

void xorSwap (int *x, int *y) {
if (x != y) {
*x ^= *y;
*y ^= *x;
*x ^= *y;
}
}

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Interview Questions

write a program to print the one dimensional array.

1 Answers  


What is pass by reference in functions?

0 Answers  


What's the difference between a linked list and an array?

14 Answers  


What are the different types of errors?

0 Answers  


Explain what is the benefit of using enum to declare a constant?

0 Answers  


What are the features of c languages?

0 Answers  


What 'lex' does?

0 Answers   Tech Mahindra,


What is wrong in this statement?

0 Answers  


what is the differnce between programing langauge and tool? is sas is a programing langauge r tool?

0 Answers   Gamesa, Satyam,


What is difference between arrays and pointers?

0 Answers  


what is a NULL pointer?

2 Answers  


How can this be legal c?

0 Answers  


Categories