write a program to swap two numbers without using temporary
variable?
Answers were Sorted based on User's Feedback
Answer / it diploma student
let a and b be the variables
a=a+b
b=a-b
a=a-b
if we take a=5 and b = 7 then
a = 5+7 = 12
b = 12-7 = 5
a = 12-5 = 7
hence swaped...
| Is This Answer Correct ? | 26 Yes | 3 No |
Answer / guest
[code]
main()
{
int a=10;
int b=20;
printf("a = %d\nb = %d\n",a,b);
a =a+b; b=a-b; a=a-b; // This is first way.
a =a*b; b=a/b; a=a/b;
printf("a = %d\nb = %d\n",a,b);
}
[/code]
[code]
main()
{
int a=10;
int b=20;
printf("a = %d\nb = %d\n",a,b);
a =a*b; b=a/b; a=a/b; //This is second way
printf("a = %d\nb = %d\n",a,b);
}
[/code]
| Is This Answer Correct ? | 19 Yes | 2 No |
Answer / sam
let a and b be variables
a^=b^=a^=b;
by performing this logic from right hand side we can swap
two variables
| Is This Answer Correct ? | 6 Yes | 5 No |
write a program to rearrange the array such way that all even elements should come first and next come odd
How can I delete a file?
Write a program to compute the similarity between two strings - The program should get the two strings as input - Then it will output one single number which is the percentage of similarity between the two strings
What is function and its example?
What is union in c?
main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } what is the output?
Are bit fields portable?
How to Throw some light on the splay trees?
hi any body pls give me company name interview conduct "c" language only
What does the c preprocessor do?
What is 1d array in c?
What are the 4 types of unions?