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 |
write a program in c language to get the value of arroy keys pressed and display the message which arrow key is pressed?
main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }
how to concatenate the two strings
#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }
how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.
0 Answers Mbarara University of Science and Technology,
To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates.
19 Answers Amazon, BITS, Microsoft, Syncfusion, Synergy, Vector,
main() { if ((1||0) && (0||1)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above
main() { char c; int i = 456; clrscr(); c = i; printf("%d", c); } a. 456 b. -456 c. random number d. none of the above
source code for delete data in array for c
why nlogn is the lower limit of any sort algorithm?
how to return a multiple value from a function?