Search



Wednesday, 11 February 2015

Swap without 3rd Variable.

In this program, int a,b statement declares 2 variables named as a & b . The 2 values
are entered by user because of scanf statement & stored in a & b which are the no.s to be
swapped . Now,using some of the  equations given below values will be interchanged
& hence swapping is done . 
For more information & explanation of this program click here..


Program to Swap without using 3rd variable.

#include<stdio.h>
#include<conio.h>
void main()
{ int a,b;
clrscr();
printf("\nprogram to swap 2 no.s");
printf("\n\nenter value of a :");
scanf("%d",&a);
printf("enter value of b :");
scanf("%d",&b);
a = a+b;
b = a-b;
a = a-b;
printf("\n now value of a = %d",a);
printf("\n now value of b = %d",b);
getch();
}


No comments:

Post a Comment

Guys if you think something is wrong or should be edit than please do comment.