Write a program for swapping of two numbers without using third variable in c.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
printf("Before interchanging a=%d and b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("After interchanging a=%d and b=%d",a,b);
getch();
}
Output:
Enter two numbers
5
6
Before interchanging a=5 and b=6
After interchanging a=6 and b=5
No comments: