Search⌘ K

Example 3: Swap Two Variables

Explore techniques to swap two variables in C by using a temporary variable or arithmetic operations. Understand how local scope affects variable swapping inside functions and apply these methods to improve your control flow skills in programming.

Problem

Write a program to interchange the contents of two variables, x and y, and print their values on the console.

Example

Input (x , y) Output (x , y)
50 , 100 100 , 50
25 , 30 30 , 25

Try it yourself

Try to solve this question on your own in the code widget below. If you get ...