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

#include<stdio.h>
#include<conio.h>

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

Output of C program to swap:

C program to swap
C program to swap



"Please Do Like Facebook Page and follow us on Twitter so that you can actively participate and develop skills in programming. If you find above post interesting do share the webpage."
This entry was posted in c program and tagged , . Bookmark the permalink.

3 Responses to C program to swap using third variable

  1. Hamza ameer says:

    how do same thing but without making an other variable??

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>