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() { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f2+=a+=2.5; printf("\n%d %d %d",a,*f1,*f2); }
how to test pierrot divisor
main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }
main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }
How to count a sum, when the numbers are read from stdin and stored into a structure?
#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }
main() { int i=5; printf("%d",++i++); }
#include<conio.h> main() { int x,y=2,z,a; if(x=y%2) z=2; a=2; printf("%d %d ",z,x); }
Develop a routine to reflect an object about an arbitrarily selected plane
main() { int i=300; char *ptr = &i; *++ptr=2; printf("%d",i); }
Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all.
2 Answers Mentor Graphics, Microsoft,
You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.