## swapping of two numbers with using third variable in c

There are many methods for swapping two numbers but this is the simplest method for swap the number with the third variable. Beginners can understand this tutorial very easily. We are creating simple Swapping of two numbers with a third variable.

#### Program

```#include<stdio.h>
int main()
{
int x,y,z; printf("n Enter first number for x :");
scanf("%d",&amp;x);
printf("n Enter second number for y :n");
scanf("%d",&amp;y);
z=x; x=y; y=z;
printf("n After Swapping the value of x is :%d", x);
printf("n After Swapping the value of y is :%d", y);
return 0; }```

Output:-
Enter first number for x :22 Enter second number for y :33 After Swapping the value of x is :33 After Swapping the value of y is :22

## Explanation of Program :

In this program, three variables are created here x,y and z. The value initialized into only two variables x & y.
We can understand by given below pattern.
x=10 and target is x=20
y=20 y=10
z = x    x value copy into z is 10
x = y    y value copy into x is 20
y = z    z value copy into y is 10

Comments to: Swapping of two numbers In C

### New Dark Mode Is Here

Get our monthly recap with the latest news, articles and resources.

Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page Welcome to Codeverb 