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 |
Implement a t9 mobile dictionary. (Give code with explanation )
1 Answers Amazon, Peak6, Yahoo,
write a origram swaoing valu without 3rd variable
main() { char c; int i = 456; clrscr(); c = i; printf("%d", c); } a. 456 b. -456 c. random number d. none of the above
void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above
why nlogn is the lower limit of any sort algorithm?
char *someFun() { char *temp = “string constant"; return temp; } int main() { puts(someFun()); }
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }
Write a program to receive an integer and find its octal equivalent?
main() { int i =10, j = 20; clrscr(); printf("%d, %d, ", j-- , --i); printf("%d, %d ", j++ , ++i); } a. 20, 10, 20, 10 b. 20, 9, 20, 10 c. 20, 9, 19, 10 d. 19, 9, 20, 10
Display the time of the system and display the right time of the other country
main() { void swap(); int x=10,y=8; swap(&x,&y); printf("x=%d y=%d",x,y); } void swap(int *a, int *b) { *a ^= *b, *b ^= *a, *a ^= *b; }
hello sir,is there any function in C that can calculate number of digits in an int type variable,suppose:int a=123; 3 digits in a.what ll b answer?