Swapping of two numbers.
Swapping of two number
This is program of swapping two number in c language.Swapping means two numbers will interchange their respective position.This is simple program in c language.Let's discuss the concept behind it.
The following method has used in the given below program
- Take two input numbers from user(let x and y).
- Assign first number to other variable(let z) of same data type.
- Then assign the value of y into x.
- And assign the value of z into y.
Swapping of two number
Let's first discuss about what is actual meaning of swapping.We will understand it with the help of an example.
Let original position of two number is X and Y
After swapping the position become Y and X
Swapping program in c language
This program has successfully run on turbo compiler.I personally use this editor for writing my program.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x ,y,z;
printf("Enter two numbers\n");
scanf("%d %d",&x,&y);
z=x;
x=y;
y=z;
printf("After swapping the numbers are\n");
printf("%d %d",x,y);
getch();
}
Swapping of two numbers.
Reviewed by Deepak kumar soni
on
December 29, 2018
Rating:
No comments: