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 |
Sir... please give some important coding questions asked by product companies..
main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }
main() { float me = 1.1; double you = 1.1; if(me==you) printf("I love U"); else printf("I hate U"); }
main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }
Is the following code legal? struct a { int x; struct a *b; }
How to access command-line arguments?
/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }
main( ) { int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(“%u %u %u %d \n”,a,*a,**a,***a); printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1); }
Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba. You can assume that all the characters will be unique.
5 Answers IITR, Microsoft, Nike,
how to delete an element in an array
main(int argc, char *argv[]) { (main && argc) ? main(argc-1, NULL) : return 0; } a. Runtime error. b. Compile error. Illegal syntax c. Gets into Infinite loop d. None of the above
main() { int i=300; char *ptr = &i; *++ptr=2; printf("%d",i); }