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 |
could you please send the program code for multiplying sparse matrix in c????
int a = 10 + 10 .... ,... A = A * A What would be the value of A? The answer is 120!! Could anyone explain this to me.
2 Answers Bosch, eInfochips, HCL, IHCL,
What is the main difference between STRUCTURE and UNION?
write a c program to Create a registration form application by taking the details like username, address, phone number, email along with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 5 users and display the details. In place of password display “****”. (Use Structures).
0 Answers CDAC, College School Exams Tests,
void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }
how to return a multiple value from a function?
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above
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() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
main() { int i =0;j=0; if(i && j++) printf("%d..%d",i++,j); printf("%d..%d,i,j); }
Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];
main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); } } a. 512, 256, 128, 64, 32 b. 256, 128, 64, 32, 16 c. 128, 64, 32, 16, 8 d. 64, 32, 16, 8, 4