Code Box
---------------------------------------------
/*program to swap two values without using third variable */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter two numbers :");
printf("\nEnter first number a= ");
scanf("%d",&a);
printf("\nEnter second number b= ");
scanf("%d",&b);
printf("\nValues before swapping a= %d & b= %d ",a,b);
a=a+b; //swapping
b=a-b;
a=a-b;
printf("\nValues after swapping a= %d & b= %d ",a,b);
getch();
}
No comments:
Post a Comment