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

What does *p++ do? What does it point to?

1007


How can you invoke another program from within a C program?

1026


Can you write the algorithm for Queue?

2032


why programs in c are running with out #include? some warnings are display in terminal but we execute the program we get answer why? eg: main() { printf("hello world "); }

1713


What is volatile keyword in c?

1000


Can we change the value of constant variable in c?

1008


WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?

2335


Difference between MAC vs. IP Addressing

1100


What is a MAC Address?

1006


What is time null in c?

1009


What are the uses of null pointers?

1037


I need a sort of an approximate strcmp routine?

988


What are loops c?

998


What is the use of getchar() function?

1076


The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none

1185