How to swap two numbers using third variable in C?

In this section you will learn how to swap two numbers in c with using third variable. We will use three variable for swapping the numbers. In this program we are assigning the default value to variable.

Swapp Two Numbers Program using third Variable

Swapping mean interchange of the values.

Let’s suppose a user will input two number as a ‘10’ and ‘20’ then we will perform swapping operation on it. We will swap the numbers with the help of third variables.

How program will work?

Program of swapping of two numbers using third variable in c.


	#include<stdio.h>
	#include<conio.h>
		
	/SWAPPING OF TWO NUMBER PROGRAM USING THREE VARIABLES
	void main()
	{
		
		int num = 10, num1 = 20, swap;
		clrscr();
		
		printf("BEFORE SWAPPING OF TWO NUMBER :- %d %d",num,num1);
		swap = num;
		num = num1;
		num1 = swap;

		printf("\nAFTER SWAPPING OF TWO NUMBER :- %d %d",num,num1);

		getch();
	}
	

Output:


	BEFORE SWAPING OF TWO NUMBER :- 10 20
	AFTER SWAPING OF TWO NUMBER :- 20 10

Post Your Comment