Program to swap 2 nos without using 3rd variable-
#include<stdio.h>
void main()
{
int a,b;
printf("Enter two numbers ");
scanf("%d %d",&a,&b);
printf("Before swaping a=%d b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swaping a=%d b=%d",a,b);
Output-
Enter two numbers 10 20
Before swaping a=10 b=20
After swaping a=20 b=10
No comments:
Post a Comment