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

how many types of operating system are avaliable?

0 Answers   IBM,


Plz sent me in .net 2.0 interview Question & answers?

0 Answers  


how to study PHP my own? i reffered many sites.. but as being a fresher i couldnt follow those... which site will be the best one?

0 Answers  


Define Abstract method & class with Example

3 Answers  


what is lazy loading in hibernate?Explain in detailed manner?

2 Answers   IBM, TCS,


Write a shell program. Enter basic pay of an employee and calculate DA, HRA, Deduction, Gross pay and Net pay as follows: DA = 75 % of BASIC HRA = 10 % of BASIC DEDUCTION = 15 % of BASIC GROSS PAY = BASIC+DA+HRA NET PAY = GROSS PAY-DEDUCTION.

1 Answers   TCS,


Which method protects back button to retrieve old value from previous page in Struts.

0 Answers  


what is client server & server? What r types of Joins? explsin it! which types of indexex in sql server? what is triggers?

0 Answers  


what are resources in case of Threads

0 Answers   Satyam,


£¢®£ž›;=9:B9<::C = ADITHI HOW TO GET?

0 Answers  


1.What is difference between symget and & in sas? 2.what is difference between callsymput and %let?

1 Answers   CitiGroup,


10.Define filters,binary to hexadecimal,hexadecimal to decimal?

0 Answers  


Categories