How to swap two variables, without using third variable ?
Answers were Sorted based on User's Feedback
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 / 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 ? | 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 |
find A^B using Recursive function
prog. to produce 1 2 3 4 5 6 7 8 9 10
main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }
Write a C function to search a number in the given list of numbers. donot use printf and scanf
write a origram swaoing valu without 3rd variable
main() { 41printf("%p",main); }8
Is this code legal? int *ptr; ptr = (int *) 0x400;
main() { extern int i; i=20; printf("%d",sizeof(i)); }
void main() { while(1){ if(printf("%d",printf("%d"))) break; else continue; } }
program to find magic aquare using array
Write a program that reads a dynamic array of 40 integers and displays only even integers
struct point { int x; int y; }; struct point origin,*pp; main() { pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y); printf("origin is (%d%d)\n",pp->x,pp->y); }