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 |
What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
Program to Delete an element from a doubly linked list.
4 Answers College School Exams Tests, Infosys,
main() { clrscr(); } clrscr();
void main() { printf(“sizeof (void *) = %d \n“, sizeof( void *)); printf(“sizeof (int *) = %d \n”, sizeof(int *)); printf(“sizeof (double *) = %d \n”, sizeof(double *)); printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *)); }
Sir... please give some important coding questions asked by product companies..
main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }
Write a single line c expression to delete a,b,c from aabbcc
void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }
write a c program to print magic square of order n when n>3 and n is odd?
Write a c program to search an element in an array using recursion
how to return a multiple value from a function?
How will u find whether a linked list has a loop or not?