Pages

Ads 468x60px

Saturday, 2 June 2012

C Program For SWAPPING VALUES


C Program For SWAPPING VALUES



C program to swap two numbers with and without using third variable, swapping
 in c using pointers, functions (Call by reference) and using bitwise XOR operator, 
swapping means interchanging. For example if in your c program you have taken
 two variable a and b where a = 4 and b = 5, then before swapping a = 4, b = 5 
after swapping a = 5, b = 4 .In our c program to swap numbers we will use a temp
 variable to swap two numbers. Swapping is used in sorting that is when we wish to
 arrange numbers in a particular order either in ascending order or in descending order.






CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the a and b value");
scanf("%d%d",&a,&b);
printf("%d %d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("%d %d",a,b);
getch();
}

0 comments:

Post a Comment

Total Pageviews