How to swap two variables, without using third variable ?
Answers were Sorted based on User's Feedback
Answer / suseela
for ex x=10,y=20
x=x+y=30(i.e 10+20)
y=x-y=10(i.e 30-20)
x=x-y=20(i.e 30-10)
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / shubham
#include<stdio.h>
#imclude<conio.h>
main()
{
int a,b;
printf("enter two number");
scanf("%d%d",&a,&b);
b=a-b;
a=a-b;
b=a+b;
printf("after swaping &d",swap);
getch();
}
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / hamsa
a=a+b;
b=a-b;
a=a-b;
ex a=2, b=4
a=2+4
b=6-4
a=6-2
ANS a=4
b=4
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / debjyoti talukder
a=a+b;
if(a>b)//only the smaller can b subtracted from greater...
b=a-b://...reverse is not possible
else
b=b-a;
a=a-b;
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / swapnil r
Swapping two variables
1. #define SWAP(x,y) x^=y^=x^=y
2. a=a+b;
b=a-b;
a=a-b;
3. use xor to swap
a = a^b
b= a^b
a= a^b
4. a=a*b;
b=a/b;
a=a/b;
Is This Answer Correct ? | 1 Yes | 3 No |
Write a routine that prints out a 2-D array in spiral order
how can i search an element in an array
2 Answers CTS, Microsoft, ViPrak,
WAP to display 1,2,3,4,5........N
main() { int i=10; void pascal f(int,int,int); f(i++,i++,i++); printf(" %d",i); } void pascal f(integer :i,integer:j,integer :k) { write(i,j,k); }
source code for delete data in array for c
write a c-program to find gcd using recursive functions
main() { extern int i; i=20; printf("%d",i); }
main() { extern out; printf("%d", out); } int out=100;
Write a Program that Inputs 10 Numbers in an Array and Show the Maximum Number
write a c-program to display the time using FOR loop
void main() { int i=10, j=2; int *ip= &i, *jp = &j; int k = *ip/*jp; printf(ā%dā,k); }
What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql