How many ways are there to swap two numbers without using
temporary variable? Give the each logic.
Answer Posted / alok bajpai
You can swap two Numbers without using temporary variable
with the help of EX-OR operator;
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the first No.:");
scanf("%d",&a);
printf("Enter the second No.:");
scanf("%d",&b);
a^=b^=a^=b;
printf("%d %d",a,b);
getch();
}
| Is This Answer Correct ? | 19 Yes | 2 No |
Post New Answer View All Answers
Explain how many levels deep can include files be nested?
write a c program for swapping two strings using pointer
What does it mean when a pointer is used in an if statement?
Explain what is wrong in this statement?
What does %d do in c?
What are the different types of endless loops?
What is s in c?
Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58
What is the purpose of sprintf?
What is string function c?
Why is it usually a bad idea to use gets()? Suggest a workaround.
What is the explanation for cyclic nature of data types in c?
which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above
How will you divide two numbers in a MACRO?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }