C Program to Swap Values of 2 Variables Without Using 3rd Variable


Couch ModePrint

/*WAP to swap values of 2 variables without using 3rd variable */
#include<stdio.h>
void main()
{
   int a,b;
   clrscr();
   printf("Enter The Value for A & B\n");
   scanf("%d%d",&a,&b);
   printf("Values Before Swapping A & B \n");
   printf("A=%d \t B=%d \n",a,b);
   a=a+b;
   b=a-b;
   a=a-b;
   printf("Values After Swapping\n ");
   printf("A=%d \t B=%d",a,b);
   getch();
}

OutPut:

Enter The Value for A & B
123
456
Values Before Swapping A & B
A=123    B=456
Values After Swapping

 A=456   B=123

Thank Your Valuable Comment Tool to Insert codes in Comments : Convert My Code. Hide

Select to parse the code (not required if code is already parsed):

Subscribe By Email

Join Our Newsletter

Get All The Latest Updates Delivered Straight Into Your Inbox For Free!

We Respect Your Privacy

Popular Posts