Explanation: This program shows how to use a temporary variable to swap two numbers. First, the user provides us with two digits. In order to switch them, we first assign the value of b to a, store the value of an in a temporary variable, and then assign the value of b to a. This guarantees that no data is lost during the exchange of the two numbers’ values.
#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
// Swapping process
temp = a; // Store value of 'a' in 'temp'
a = b; // Assign value of 'b' to 'a'
b = temp; // Assign value stored in 'temp' (which is 'a') to 'b'
printf("After swapping: a = %d, b = %d\n", a, b);
return 0;
}