swap two number wthout using third variable

Answers were Sorted based on User's Feedback



swap two number wthout using third variable..

Answer / jvhariharan

void main()
{
int a=10,b=20;
a=a+b;
b=a-b;
a=a-b;
}

Is This Answer Correct ?    24 Yes 3 No

swap two number wthout using third variable..

Answer / ashutosh tiwari

void swap_num(int *a, int *b)
{
*a = *a+*b; *b = *a-*b; *a = *a-*b;
}
or
void swap_num(int *a,int *b)
{
*a = *a^*b; *b = *a^*b; *a = *a^*b;
}

Is This Answer Correct ?    8 Yes 0 No

swap two number wthout using third variable..

Answer / suyog

A very simple and cute answer...

Assign as follows

a=a+b-(b=a)

Is This Answer Correct ?    6 Yes 0 No

swap two number wthout using third variable..

Answer / abhay khare

void main()
{
int a,b,c
printf("two no are\n");
scanf("%d&n");
a=c;
b=a
c=b
getch;
}

Is This Answer Correct ?    1 Yes 10 No

Post New Answer

More Programming Languages AllOther Interview Questions

What is the use of Differ interface check box in Ship confirm?

0 Answers  


How to swap two String values without using a third variable?

8 Answers   Infosys,


what is the difference between a namespace and assembly ?

4 Answers   Innominds, Polaris,


What are the other ways to create an object with out calling new keyword in java?

2 Answers   HCL,


what is the use of check point

1 Answers   HP,


hi i m deepak my shedule for NIC pi is 17 Apr please contact me if anybody has interview on same day or give me some idea who have faced

0 Answers  


What is a singleton linked list?

1 Answers   Wipro,


What is the difference between: x=a+b+c+d; and x=SUM(a,b,c,d);?sas

5 Answers  


There is a room with 1000 light switches, numbered 1, 2, 3, 4, ... 1000, all turned off. Outside the room there are 1000 men, numbered man1, man2, ...man 1000 In order, each man walks into the room and changes the position of each switch that is a multiple of his number. That is: man1 flips every switch man2 flips switches 2, 4, 6, 8 ....1000 man3 flips switches 3, 6, 9, ..... 999 ..... Man 1000 flips switch 1000 After all 1000 men are done, how many switches are on?

3 Answers  


73. How can you set the status and title for a modal dialog box? a) In the attributes of the corresponding screen. b) Before the corresp. call screen statement. c) In a PBO module of the corresponding screen. d) In the PAI module of the corresponding screen.

1 Answers  


if heap sort contains n elements, no of comparsions required are

2 Answers   Hughes,


class A{ void me(){s.o.p("");} class B extends A{ void me() {s.o.p(" ");} class M{ A a=new B(); B b=new A(); a.me(); b.mne();} what is the output of this, how?

2 Answers   Cosmos, HyTech Pro, WinSoft,


Categories