swap two integer variables without using a third temporary
variable?
Answers were Sorted based on User's Feedback
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\n ENTER 2 VALUES : ");
scanf("%d%d",&a,&b);
printf("\n THE VALUES BEFORE SORTING : %d,%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\n THE VALUES AFTER SORTING : %d,%d",a,b);
getch();
}
| Is This Answer Correct ? | 40 Yes | 1 No |
the best way what i choose is that : if x=89 , y=-88
x^=y^=x^=y;
this line will swap the above numbers......
thank u
| Is This Answer Correct ? | 10 Yes | 5 No |
Answer / sumit salve
a=a+b-(b=a);
or
a=a*b/(b=a);
this will also swap two numbers!!!
Thank You...
| Is This Answer Correct ? | 0 Yes | 0 No |
i'll only give u logic #include<stdio.h>
void main() { int a=10,b=20;
printf("b4 swap:a=%d b=%d",a,b);
a=a+b;b=a-b;a=a-b; printf("aftr
swap:a=%d b=%d",a,b); }
from-onkar.koparde@gmail.com
| Is This Answer Correct ? | 2 Yes | 4 No |
How to find the given no is odd or even without checking of any condition and loops. (Hint: Using array)
write a program to copy a string without using a string?
Tell me what is null pointer in c?
Is multithreading possible in c?
Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?
difference between Low, Middle, High Level languages in c ?
What do you mean by c?
How to calculate Total working time using Login and logout?
2 Answers CTS, Cygnus, Infosys, Signal Networks, TCS, Wipro,
What is the use of #include in c?
what is the use of pointers
What is pass by reference in functions?
What are all different types of pointers in c?