How to swap two variables, without using third variable ?
Answers were Sorted based on User's Feedback
Answer / saddi srikanth
if x=14, y=18
x=x+y;
now x=14+18=32;
y=x-y;
now y=32-18=14;
now again y=14
x=x-y;
now x=32-14=18
final answer is:
x=18, and y=14
u can try this formule by taking any values for x and y.
| Is This Answer Correct ? | 4 Yes | 5 No |
Answer / avanthi kothakonda
i want to swapping without using any third variable and
opartion
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / mohit prakash saxena
2 answer will not work if the value of a is +ve and b is negative try for a=2 and b=-2
| Is This Answer Correct ? | 2 Yes | 3 No |
Answer / swamy
class SwapDemo
{
int a,b;
void swap(int a,int b)
{
a=a+b;
b=a-b;
a=a-b;
}
public static void main(String args[])
{
SwapDemo s=new SwapDemo();
s.swap(12,14);
}
}
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / mujtaba
answer 1 is the right 1:i.e
a=a+b;
b=a-b;
a=a-b;
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / mahesh
class swap_two_verible_use
{
public static void main(String args[])
{
int a=50;
int b=20;
System.out.println("A = "+a);
System.out.println("B = "+b);
System.out.println("-----------------");
System.out.println("After swiping");
a=a+b;
b=a-b;
a=a-b;
System.out.println("A = "+a);
System.out.println("B = "+b);
}
}
| Is This Answer Correct ? | 1 Yes | 2 No |
void pascal f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } void cdecl f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } main() { int i=10; f(i++,i++,i++); printf(" %d\n",i); i=10; f(i++,i++,i++); printf(" %d",i); }
Design an implement of the inputs functions for event mode
Write a program to receive an integer and find its octal equivalent?
main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }
main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); }
main() { int i=4,j=7; j = j || i++ && printf("YOU CAN"); printf("%d %d", i, j); }
write a program in c language to get the value of arroy keys pressed and display the message which arrow key is pressed?
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?
main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4}; int **ptr = p; ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *++ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); ++*ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); }
why java is platform independent?
main() { int i = 3; for (;i++=0;) printf(“%d”,i); }
write a program to Insert in a sorted list