Write a program to swap two numbers in C language.
In other words,
Write a program to exchange the values of two variables in C language.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
DOWNLOAD ATTACHMENT FOR ANSWER:
#include <stdio.h>
int main()
{
int x,y,z;
printf(“Enter two values: “);
scanf(“%d%d”,&x,&y);
z=x;
x=y;
y=z;
printf(“x=%d and y=%d”,x,y);
}
For Example:
If, x=5 and y=10
We put the value of x in z.
z=x
z=5
After that, we put the value of y in x.
x=y
x=10
Finally, we put the value of z in y.
y=z
so, y=5
And, Run the program to print x=10 and y=5