Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How many ways are there to swap two numbers without using
temporary variable? Give the each logic.

Answer Posted / tumatij

/*5. Write a C program to swap two integer numbers in various different techniques.
Answer:
*/
#include<stdio.h>
int main()
{
int a,b,temp;
printf("Enter the two numbers:");
scanf("%d%d",&a,&b);
printf("
Values before swapping a=%d b=%d",a,b);
//First logic
temp=a;
a=b;
b=temp;
printf("
Values after swapping a=%d b=%d",a,b);
//2nd logic
a=a+b;
b=a-b;
a=a-b;
printf("
Values after swapping a=%d b=%d",a,b);
//3rd logic
a=a*b;
b=a/b;
a=a/b;
printf("
Values after swapping a=%d b=%d",a,b);
//4th logic
a=(a+b)-(b=a);
printf("
Values after swapping a=%d b=%d",a,b);
//5th logic
a=a^b;
b=a^b;
a=a^b;
printf("
Values after swapping a=%d b=%d",a,b);
//6th logic
a^=b^=a^=b;
printf("
Values after swapping a=%d b=%d",a,b);
//7th logic
a=a-b;
b=a+b;
a=b-a;
printf("
Values after swapping a=%d b=%d",a,b);
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a program in c to replace any vowel in a string with z?

1115


Why is python slower than c?

1076


Why is #define used?

1273


write a program to concatenation the string using switch case?

2089


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

2147


What is the difference between far and near in c?

1065


number of times a digit is present in a number

2035


What is c preprocessor mean?

1305


any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above

1044


How can you check to see whether a symbol is defined?

1098


What is variable and explain rules to declare variable in c?

1082


How would you rename a function in C?

1037


In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

1222


explain what is a newline escape sequence?

1084


Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me

1944