We can enter two numbers and the code will display the values by interchanging them. By developing this simple code we will learn how to enter data by scanf and how to display them after swapping them using printf command.
Here is the code
#include <stdio.h>
int main(void){
int num1,num2,num3; // declaring variables as integers
printf("Enter the two numbers ");
scanf("%d %d",&num1,&num2); // Enter two numbers
num3=num2; // Storing the value of num2 in num3
num2=num1; // Shifting the value of num1 to num2
num1=num3; // Assign the value of num3 ( original num2 value) to num1
printf(" Two numbers are %d,%d " ,num1, num2); // printng outputs
return 0;
}
We can ask users to enter two data and then display them in reverse order.