My Project - Video Waker Alarm
Get Video alarm on Google Play

C program to swap using third variable

c program to swap two numbers using third variable : Hello! This c program is very important as it is mostly taught and asked in external, vivas and in campus recruitment exams also.Swap two numbers means interchanging the value of one variable to another. We are Swapping the value of variable ‘a’ and ‘b’ by using a third variable ‘temp’. While by using some tricks you can make c program to swap two numbers without using third variable. Lets look on this c program to swap two numbers using third variable. If you like to know about call by reference and call by value, see the examples of swapping that i have taken i.e as c program to swap two numbers using call by value and using call by reference.

C program to swap


int main()
    int a,b,temp;
    printf("enter two values\n"); 
    printf("\na = ");
    printf("\nb = ");
    printf("\na = %d\tb = %d ", a, b);

Output of C program to swap:

C program to swap
C program to swap

8 thoughts on “C program to swap using third variable”

      1. Here you go

        As you know that
        7 multiply by 4 is equal to 28
        4 multiply by 7 is also equal to 28

        We can use the similar approach to swap values of variables

        For Example like this


        x=y*x; //x=6
        y=x/y; //y=3
        x=x/y; //x=2

        I hope it was helpful for you 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *