/* The Following program is used to swap 2 values without the need of 3rd variable. The C code below utilizes the addition & subtraction to perform this operation */
#include<stdio.h>#include<conio.h>
int main()
{
float a,b;
printf("Enter 2 Numbers to be swaped \n");
scanf("%f%f",&a,&b);
printf("Before Swapping a=%f b=%f\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("After swapping a=%f b=%f\n",a,b);
getch();
return 0;
}
--------------------------------------------------------------------------------------------------------------------
/* The
Following program is used to swap 2 values without the need of 3rd
variable. The C code below utilizes the multiplication & division to
perform this operation */
#include<stdio.h>
#include<conio.h>
int main()
{
float a,b;
printf("Enter 2 Numbers to be swaped \n");
scanf("%f%f",&a,&b);
printf("Before Swapping a=%f b=%f\n",a,b);
a=a*b;
b=a/b;
a=a/b;
printf("After swapping a=%f b=%f\n",a,b);
getch();
return 0;
}
Screenshot:
![C program to Swap 2 Numbers Without Using third variable C program to Swap 2 Numbers Without Using third variable](http://3.bp.blogspot.com/-6q_cLlQ_zAM/UqXEjIIA2xI/AAAAAAAAKA8/fCz60vQch4Q/s400/swap.png)
0 comments:
Post a Comment