How to swap two variables, without using third variable ?
Answers were Sorted based on User's Feedback
Answer / marutikutre
x = y | (y=x)-x;
&
a=a*b/(b=a); provided either of a or b is not 0
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / mrx
In assembly language you could use "xchg" instruction witch
swaps the two variables in one instruction.
/* swaps %dest <-> %source */
xchg %dest, %source
/* inline assambly example for C language */
void swap(int register *x, register int *y)
{
asm("xchg %0, %1;" \
: "=r"(*x), "=r"(*y)
: "0"(*x), "1"(*y)
);
}
This is the fastest method you can achieve in hand
optimization. I think C compiler will do the same trick if
possible.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / simhachalam lakkakula
Answer 4 get fail for the following values
Before: a= 219455078, b= -747788332
After: a= -875186568, b= 1
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / simhachalam lakkakula
Answer 4
Logic:
a=a*b;
b=a/b;
a=a/b;
get fail for the following values
Before: a= 219455078, b= -747788332
After: a= -875186568, b= 1
| Is This Answer Correct ? | 1 Yes | 0 No |
---------------------
a=a*b
b=a/b
a=a/b
---------------------
a=a+b
b=a-b
a=a-b
----------------------
a = a Xor b
b= a Xor b
a= a Xor b
----------------------
all above three methods are correct, i hv checked...
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / rahul
I am new in C/C++.
How to write the program for second answer. Does it
automatically convert the numbers in binary by using ^ sign.
:}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / devarajan.k
a[12]=name
b[20]=name
Here the size 12 & 25 has no effect hence we can change
the size
a[]=name
b[]=name
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / poojamnagal
Num1 = 5
Num2 = 7
Num1 = 5+7 = 12
Num2 = 12- 7 = 5
Num1 = 12-5 = 7
So, Now Num1 = 7
Num2 = 5
| Is This Answer Correct ? | 2 Yes | 2 No |
write a program for area of circumference of shapes
Write a C program to print look and say sequence? For example if u get the input as 1 then the sequence is 11 21 1211 111221 312211 12112221 .......(it counts the no. of 1s,2s etc which is in successive order) and this sequence is used in run-length encoding.
main() { int i, j, *p; i = 25; j = 100; p = &i; // Address of i is assigned to pointer p printf("%f", i/(*p) ); // i is divided by pointer p } a. Runtime error. b. 1.00000 c. Compile error d. 0.00000
main() { int i=300; char *ptr = &i; *++ptr=2; printf("%d",i); }
typedef struct error{int warning, error, exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); }
How to return multiple values from a function?
main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }
How to swap two variables, without using third variable ?
104 Answers AB, ADP, BirlaSoft, Cisco, Cygnet Infotech, HCL, Hewitt, Honeywell, HP, IBM, Infosys, Manhattan, Microsoft, Mobius, Percept, Satyam, SofTMware, TCS, Wipro, Yamaha,
main() { while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”); }
write a program in c language to get the value of arroy keys pressed and display the message which arrow key is pressed?
Write a program using one dimensional array to assign values and then display it on the screen. Use the formula a[i]=i*10 to assign value to an element.
1 Answers Samar State University,
Hi, i have a project that the teacher want a pyramid of numbers in C# or java...when we click a button...the pyramid should be generated in a listbox/or JtextArea...and the pyramid should have the folowing form: 1 232 34543 4567654 567898765 67890109876 7890123210987 890123454321098 90123456765432109 0123456789876543210 Plz help with codes...didn't find anything on the net.