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...


how to swap two integers 1 and 32767 without using third
variable

Answers were Sorted based on User's Feedback



how to swap two integers 1 and 32767 without using third variable..

Answer / pandi

a=1;
b=32767;
a=a+b;
b=a-b;
a=a-b;

Is This Answer Correct ?    43 Yes 7 No

how to swap two integers 1 and 32767 without using third variable..

Answer / riya ganguly

int a=1,b=32767;
a=a+b;
b=a-b;
a=a-b;
printf("a=%d,b=%d",a,b);

Is This Answer Correct ?    17 Yes 5 No

how to swap two integers 1 and 32767 without using third variable..

Answer / mansi_engg

use unsigned before variable a and b in
a=1;
b=32767;
a=a+b;
b=a-b;
a=a-b;
bcoj 32767+1 =32768 which goes out of range of integer and
will be stored as -32768 which wil make the swapping
wrong.by using unsigned, addition will come in range 0-65536
and thus the process works.

Is This Answer Correct ?    8 Yes 2 No

how to swap two integers 1 and 32767 without using third variable..

Answer / sharath kumar

As int max valur is 32767. If we increment it it becomes -32768, so its a wrong way to do

a=1; b=32767;
a=-a; b=-b;
a=a+b; //-32768 with in range
b=a-b; //-1
a=a-b; //-32767
printf("%d%d",-a,-b);

Is This Answer Correct ?    4 Yes 0 No

how to swap two integers 1 and 32767 without using third variable..

Answer / g.sai lakshmi priyanka

void main()
{
 int a,b;
 a=32767,b=1;
 a=a*b;
 b=a/b;
 a=a/b;
 printf("%d %d",a,b);
}
 EXPLAINATION:
 
a=32767*1=32767
b=32767/1=32767
a=32767/32767=1

a=1,b=32767

Is This Answer Correct ?    3 Yes 0 No

how to swap two integers 1 and 32767 without using third variable..

Answer / vidhubala-j

int a=1
int b=32767
a^=b^=a
printf("%d %d",a,b);

Is This Answer Correct ?    4 Yes 3 No

how to swap two integers 1 and 32767 without using third variable..

Answer / usama

take two var a , b
a=a+b;
b=a-b;
a=a-b;

Is This Answer Correct ?    2 Yes 1 No

how to swap two integers 1 and 32767 without using third variable..

Answer / sathwika

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

Is This Answer Correct ?    3 Yes 2 No

how to swap two integers 1 and 32767 without using third variable..

Answer / jonu

a=1;
b=32767;

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

printf("%d %d",a,b);

Is This Answer Correct ?    2 Yes 1 No

how to swap two integers 1 and 32767 without using third variable..

Answer / mani654mani

Int var1=1, var2=32767;
var1 = var1 + var2;
var1 = 1 + 32767 =32768;

var2 = var1 - var2;
var2 = 32768 - 32767 = 1;

var1 = var1 - var2;
var1 = 32768 - 1 = 32767;

So Now var1 = 32767 and var2 = 1

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset

0 Answers  


Why do we need arrays in c?

0 Answers  


a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above

0 Answers  


Write a program to find whether the given number is prime or not?

6 Answers  


What is extern variable in c with example?

0 Answers  


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.

0 Answers   IBM,


what is diffrence between string and character array?

1 Answers  


what is difference between getchar,putchar functions and printf and scanf function? does putchar show output only when input given to it

5 Answers   DIT,


What are the disadvantages of external storage class?

0 Answers  


what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }

9 Answers  


write a program to find lcm and hcf of two numbers??

1 Answers  


In how much time you will write this c program? Prime nos from 1 to 1000

2 Answers   TCS,


Categories