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() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }
Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };
Write a program that find and print how many odd numbers in a binary tree
main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a); } abc(char a[]){ a++; printf("%c",*a); a++; printf("%c",*a); }
#define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE"); }
write a c-program to display the time using FOR loop
void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }
Cau u say the output....?
how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.
0 Answers Mbarara University of Science and Technology,
#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }
Give a one-line C expression to test whether a number is a power of 2.
4. Main() { Int i=3,j=2,c=0,m; m=i&&j||c&I; printf(“%d%d%d%d”,I,j,c,m); }