Interchange Two Numbers in C
Q. Write a C program to interchange the value of two variables using a third variable.
#include
#include
void main()
{
int x, y, t;
clrscr();
printf("Enter two numbers: ");
scanf("%d%d", &x, &y);
printf("Before interchange(swapping) the numbers\nx= %d\ty= %d\n", x, y);
t = x;
x = y;
y = t;
printf("After interchange(swapping) the numbers\nx= %d\ty= %d", x, y);
getch();
}
Q. Write an algorithm to Interchange Two Numbers with third variable in C.
Step 1: Start Step 2: Declare three integer variables `x`, `y`, and `t` Step 3: Prompt the user to enter two numbers Step 4: Read the two integer inputs and store them in `x` and `y` Step 5: Display the values of `x` and `y` before swapping Step 6: Assign the value of `x` to temporary variable `t` Step 7: Assign the value of `y` to `x` Step 8: Assign the value of `t` (which holds original `x`) to `y` Step 9: Display the values of `x` and `y` after swapping Step 10: End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com