How to swap two variables, without using third variable ?
Answers were Sorted based on User's Feedback
Answer / vinay kumar shukla
i am not giving answer
all above answer for swaping integer type variables without
third
i want answer in string type
Is This Answer Correct ? | 6 Yes | 15 No |
Answer / saumya
Thanks a lot guys. It is giving very good analysis.
Is This Answer Correct ? | 7 Yes | 19 No |
Answer / koneru gowtham
plz check 3 aswer is perfect, 2 one mat be wrong in some cases
Is This Answer Correct ? | 47 Yes | 63 No |
Answer / kumar
Using Assembly language( Using Accumulator)...Without using
any arithmatic...without using any Pointer...without
declaring third varible
int a = 20;
int b = 10;
__asm
{
mov EAX,b
push EAX
mov EAX,a
mov b,EAX
pop EAX
mov a,EAX
}
Is This Answer Correct ? | 17 Yes | 33 No |
Answer / meenama
The first two answers are correct. Third will FAIL in the
case the second num is 0. The #19 one still uses a third
variable.
Is This Answer Correct ? | 5 Yes | 21 No |
Answer / mangesh
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
clrscr();
printf("\nEnter two numbers:");
scanf("%d%d",&a,&b);
printf("\nThe numbers after swapping are %d %d",b,a);
getch();
return 0;
}
Is This Answer Correct ? | 0 Yes | 18 No |
Answer / rehan
#include<stdio.h>
main()
{
int a,b;
printf("Enter any two numbers\n");
scanf("%d%d",&a,&b);
printf("The values before swapping are\n%d %d\n",a,b);
swap(&a,&b);
printf("The values after swapping are\n%d %d\n",a,b);
getch();
}
swap(*x,*y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
Is This Answer Correct ? | 5 Yes | 24 No |
main ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); }
main() { int i=3; switch(i) { default:printf("zero"); case 1: printf("one"); break; case 2:printf("two"); break; case 3: printf("three"); break; } }
Print an integer using only putchar. Try doing it without using extra storage.
void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }
void main() { int const * p=5; printf("%d",++(*p)); }
3 Answers Infosys, Made Easy, State Bank Of India SBI,
source code for delete data in array for c
What is data _null_? ,Explain with code when u need to use it in data step programming ?
#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }
write a program to Insert in a sorted list
what is the code of the output of print the 10 fibonacci number series
Finding a number which was log of base 2
What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */ } ii. int abc(a,b) int a; float b; { /* some code*/ }