Code Samples C

Swap 2 variables without using 3rd variable

Code ResourceAuthor: deepu08  

Difficulty Level: Beginner

Published: 3rd Jun 2009   Read: 23981 times  

Filed in: C
Add Comment



Sponsored Links



This program swaps 2 varibles with out using of 3rd variable.


Sample Code
  1. #include<stdio.h>
  2. void main()
  3. {
  4.  int a,b;
  5.  printf("enter 2 numbers");
  6.  scanf("%d %d",&a,&b);
  7.  printf("nthe 2 numbers are %d %d",a,b);
  8.  a=a^b;
  9.  b=a^b;
  10.  a=a^b;
  11.  printf("n the 2 numbers are %d %d",a,b);
  12. }

Next Article: Modified String Encryption


Latest Code Samples


Popular Code Samples


Related Code Samples


Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 


it's good
Comment posted by: manoranjith on 2010-08-20T07:06:48
Hi Imran T Patel here If any thing Wrong with this Program please forward to me...
We can also Write Swap Program with using pointer but without using 3rd Variable

void main()
int a=10;
int b=20;
printf("n THe value of-------- a---%d b---%d",a,b);

Comment posted by: Imran T Patel on 2010-08-30T07:11:10
Good !
Comment posted by: Mainak Dutta on 2011-03-14T23:09:14
how to code for 20x4 lcd using embedded c in mp lab
Comment posted by: Raghu on 2011-03-08T05:41:11

Popular Coders

# Coder NameHits
1. kaivalya198959987
2. mano.mithun52040
3. deepu0823982
4. sadasivathavamani21861
5. venkatakrishnansvpr18400
6. Jimmy Zorald16627
7. meefriend4ever12482
8. shashivaishnav12372
9. chandrikakr12336
10. Charles Pergiel10995

Active Coders

Refined Tags