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 |
Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.
There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong? void main() { struct student { char name[30], rollno[6]; }stud; FILE *fp = fopen(“somefile.dat”,”r”); while(!feof(fp)) { fread(&stud, sizeof(stud), 1 , fp); puts(stud.name); } }
what will be the position of the file marker? a: fseek(ptr,0,SEEK_SET); b: fseek(ptr,0,SEEK_CUR);
Implement a t9 mobile dictionary. (Give code with explanation )
1 Answers Amazon, Peak6, Yahoo,
main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }
#define DIM( array, type) sizeof(array)/sizeof(type) main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr, int)); }
main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }
find simple interest & compund interest
Write a procedure to implement highlight as a blinking operation
Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines
union u { union u { int i; int j; }a[10]; int b[10]; }u; main() { printf("\n%d", sizeof(u)); printf(" %d", sizeof(u.a)); // printf("%d", sizeof(u.a[4].i)); } a. 4, 4, 4 b. 40, 4, 4 c. 1, 100, 1 d. 40 400 4
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,