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 |
how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1 loop) and maximum 2 variables using C.
19 Answers Cap Gemini, Infosys,
Print an integer using only putchar. Try doing it without using extra storage.
#include<stdio.h> main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } }
PROG. TO PRODUCE 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql
main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { printf(ā%dā ,*a); a++; } p = a; for(j=0; j<5; j++) { printf(ā%d ā ,*p); p++; } }
to remove the repeated cahracter from the given caracter array. i.e.., if the input is SSAD output should of SAD
Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];
Write a program to receive an integer and find its octal equivalent?
Write a program to implement the motion of a bouncing ball using a downward gravitational force and a ground-plane friction force. Initially the ball is to be projected in to space with a given velocity vector
main() { float f=5,g=10; enum{i=10,j=20,k=50}; printf("%d\n",++k); printf("%f\n",f<<2); printf("%lf\n",f%g); printf("%lf\n",fmod(f,g)); }
main() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }