Write a C program to swap value of two variables using the third variable.

Description:

You need to create a C program to swap values of two variables using the third variable.

Hint:

You can use a temp variable as a blank variable to swap the value of x and y.

Conditions:

  • Take three variables for eg. x, y and temp.
  • Swap the value of x and y variable.
#include <stdio.h>
int main()
{
  int x = 10;
  int y = 20;
  int temp;

  temp = x;
  x = y;
  y = temp;

  printf("X=%d	Y=%d", x, y);
  return 0;
}
Tutorials Class - Output Window

X=20 Y=10


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.