//Swapping of two numbers without using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the value of a:");
scanf("%d",&a);
printf("Enter the value of b:");
scanf("%d",&b);
b=a+b;
a=b-a;
b=b-a;
printf("After swapping:\n");
printf("a=%d and b=%d",a,b);
getch();
}
Output:
Enter the value of a:5Enter the value of b:4
After swapping:
a=4 and b=5
No comments:
Post a Comment