c programming – Swap two variable without using 3rd variable

c programming – Swap two variable without using 3rd variable

In this post we will show you how to Swap two variable without using 3rd variable in c programming. flowing code will help you to perform program.
For Swap two variable without using 3rd variable we use this method ::
a=a+b;
b=a-b;
a=a-b;

// include header file 
# include <stdio.h>
# include <conio.h>
// main function
void main()
{
	int a,b;
	clrscr();
	
	// insert data
	printf("Enter A: ");
	scanf("%d",&a);
	printf("Enter B: ");
	scanf("%d",&b);

	// print BeforeSwap
	printf("\nBefore Swap:");
	printf("\nValue of A is: %d",a);
	printf("\nValue of B is: %d",b);
	
	// Swap data
	a=a+b; 
	b=a-b; 
	a=a-b;

	// print Swap result
	printf("\n\nAfter Swap:");
	printf("\nValue of A is: %d",a);
	printf("\nValue of B is: %d",b);
	getch();
}

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  72  =  75

We accept paid advance and paid guest Posting on our Site : Contact US