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.
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.
#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(); }
BEFORE SWAPING OF TWO NUMBER :- 10 20 AFTER SWAPING OF TWO NUMBER :- 20 10