HOW TO SWAP TWO NOS IN ONE STEP?

Answers were Sorted based on User's Feedback



HOW TO SWAP TWO NOS IN ONE STEP?..

Answer / shiva kumar

void main()
{
int a,b;
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
b=a+b-(a=b);
printf("%d %d ",a,b);
}

Is This Answer Correct ?    28 Yes 7 No

HOW TO SWAP TWO NOS IN ONE STEP?..

Answer / rajkumar

(a=a-(b=(a=a+b)-b));

Is This Answer Correct ?    9 Yes 3 No

HOW TO SWAP TWO NOS IN ONE STEP?..

Answer / ashik

#define swap(a,b) a^=b^=a^=b;

Is This Answer Correct ?    6 Yes 4 No

HOW TO SWAP TWO NOS IN ONE STEP?..

Answer / sasikumar

main()
{
int a,b,c;
printf("enter two no's :");
scanf("%d%d",&a,&b);
c=a^=b^=a^=b;
printf("%d",c);
}

Is This Answer Correct ?    6 Yes 6 No

HOW TO SWAP TWO NOS IN ONE STEP?..

Answer / vijay

#include<stdio.h>
main()
{
int a=5,b=9;
printf("%d %d \n",a,b);
a^=b^=a^=b;
printf("%d %d \n",a,b);
}

Is This Answer Correct ?    4 Yes 4 No

HOW TO SWAP TWO NOS IN ONE STEP?..

Answer / sumit

b=abs((a=b)-(a+b));

Is This Answer Correct ?    1 Yes 1 No

HOW TO SWAP TWO NOS IN ONE STEP?..

Answer / eswaran

Sasi kumar answer is very wrong answer .....

Is This Answer Correct ?    0 Yes 0 No

HOW TO SWAP TWO NOS IN ONE STEP?..

Answer / venkatesh sabinkar

#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=2,t;
clrscr();
printf("a=%d,b=%d",a,b,b=t,a=b,t=a);
getch();
}

Is This Answer Correct ?    3 Yes 4 No

HOW TO SWAP TWO NOS IN ONE STEP?..

Answer / z

Trick question: the phrase "one step" is undefined.
Example: how many steps are there in the following statement?
a = ++b;

Is This Answer Correct ?    0 Yes 1 No

HOW TO SWAP TWO NOS IN ONE STEP?..

Answer / amaresh chandra das

amaresh@Hare-Krishna:~$ cat swp.c
#include<stdio.h>
int
main(){
int a=5,b=6; // Compile using gcc -Wall
#ifdef DEBUG // to avoid compiler warnings
a ^=b^=a^=b;
#endif
printf("value of a is %d and b is %d\n",a,b);
return 0;
}

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More C Interview Questions

which is the best site or book for learning C...and i need the content for C..how to get the good programming skills....? can plz suggest me....

2 Answers  


‎How to define structures? · ‎

0 Answers  


Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?

0 Answers  


How to set a variable in the environment list?

1 Answers  


what is the use of using linked list and array?

10 Answers   Infosys, TCS,






What are the various topologies? Which one is the most secure?

2 Answers  


WAP to accept first name,middle name & last name of a student display its initials?

5 Answers   AITH, NIIT,


write a program to compare 2 numbers without using logical operators?

5 Answers   IBM,


The file stdio.h, what does it contain?

0 Answers  


Q-1: Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college.

8 Answers  


What should malloc() do? Return a null pointer or a pointer to 0 bytes?

0 Answers  


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.

0 Answers   IBM,


Categories