PROGRAM: Write a C program to swap two numbers without using 3rd variable.
#include<stdio.h>
main()
{
int a,b;
printf("Enter a\n");
scanf("%d",&a);
printf("Enter b\n");
scanf("%d",&b);
printf("The values of a is %d
and b is %d before swaping\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("The values of a is %d
and b is %d after swaping\n",a,b);
main()
{
int a,b;
printf("Enter a\n");
scanf("%d",&a);
printf("Enter b\n");
scanf("%d",&b);
printf("The values of a is %d
and b is %d before swaping\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("The values of a is %d
and b is %d after swaping\n",a,b);
}
OUTPUT:-
Enter a
30
Enter b
35
The values of a is 30 and b is 35 before swaping
The values of a is 35 and b is 30 after swaping
30
Enter b
35
The values of a is 30 and b is 35 before swaping
The values of a is 35 and b is 30 after swaping
0 Comments