C program for Swapping of two Numbers in an easy way. The questions may be asked for this C program is, Write a simple swapping of 2 numbers program in C language. & find the swap of few numbers using C source code. It is an useful C program for beginners.
[Read: C program for simple interest calculation]
SWAPPING TWO VALUE IN C
Swapping 2 numbers in C program and this is used to swap the 2 numbers without using third variable or with the use of third variable. It makes the first value to assign the temp variable and next one is to assign the value2 for value 1 and finally assign the temp value to value2 and display it as an output.
[Useful: Education Loan Guide] & [Study Abroad Details]
SWAP PROGRAM:
/* Title: Swap of 2 Numbers Author: Vinoth Selvaraj © http://students3k.com */ //Header files #include <stdio.h> #include <conio.h> void main() { //Program variables int value1,value2,temp; clrscr();//Function used to clear previous output printf("Enter first value "); //Display function scanf("%d",&value1); //Getting value function printf("Enter second value : "); scanf("%d",&value2); //Calculation for swapping two numbers temp=value1; value1=value2; value2=temp; printf("After swapping value1 = %d and value2 = %d",value1,value2); getch(); }
SWAP PROGRAM’S OUTPUT:
Enter first value: 12
Enter second value: 15
After swapping value1 and value2=15
12