Write a program that swaps and displays the values of three integer variables A, B, C entered on the keyboard: A ==> B , B ==> C , C ==> A


Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>

int main()
{
    int A, B, C , aux;
    
    printf("Enter 3 integer values: ");
    scanf("%d %d %d", &A, &B, &C);
    // first we have saved the old value of A in aux
    // second, the value of C is transfered to A 
    // third, the value of B is transfered to C 
    // fourth,the value of A is transfered to B 
    aux = A ;
    A = C ;
    C = B;
    B = aux ;
    
    printf("A = %d, B = %d, C = %d\n",A,B,C);

    return 0;
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Recursive function to convert a decimal integer to binary