C Program To Swap Two Numbers Using Three Variables

C Program To Swap Two Numbers Using Three Numbers – If you are looking for swapping C program, this article will guide you to lean swapping two numbers in C using 3 variables. Just go through this swapping tutorial you will able write a program to swap two numbers using three variable a,b and c.

We are publishing series of C programs for beginners, students, B.Tech graduates to enhance their C programming skills and hands-on experience on coding. This is the second C programming example in the series, it helps newbies in reaching their goals in the career. All the best guys in learning c programming with coding compiler blog.

C Program To Swap Three Numbers

Swapping in C programming language can be done using various techniques, like using two variables, three variables, and functions, but here in this swapping program, we used three variables to perform swap two numbers in C.

C Program To Swap Three Numbers Source Code

Copy paste the below source code or write your own logic into C compilers and run the program to see the result.

/* Swapping 2 Using Three Variables In C - SWAPTWONUMBERS.C */

#include<stdio.h>
#include<conio.h>
void main()
{
    int a, b, c ;
    clrscr() ;
    printf("Enter two numbers : ") ;
    scanf("%d %d", &a, &b) ;
    printf("\nBefore swapping : \n\n") ;
    printf("a = %d \t b = %d", a, b) ;

    /* Swapping Two Numbers Logic */
    c = a ;
    a = b ;
    b = c ;
    printf("\n\nAfter swapping : \n\n") ;
    printf("a = %d \t b = %d", a, b) ;
    getch();
}

C Program To Swap Two Numbers Output

After you compile and run the above program, your C compiler asks you to enter two numbers to swap, then it will show output before swapping and after swapping two numbers like below expected output.

Enter two numbers: 10 20

Before swapping :
a = 10 b = 20

After swapping :
a = 20 b = 10

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers – If you are looking for swapping program in C language, this article will help you to lean swapping two numbers in C. Just go through this blog post you will able write a program to swap two numbers using two variable num1 and num2.

We are going to publish series of C programs for beginners, students, B.Tech graduates to enhance their programming skills and hands on experience on coding. So it helps in reaching their goals in career. All the best guys in learning c programming with coding compiler blog.

C Program To Swap Two Numbers

Swapping in C language can be done using various techniques, here in this swapping program we used two variables to perform swap two numbers.

C Program To Swap Two Numbers Source Code

Copy paste the below source code in to c compilers and run the program to see the the result.

/* Swapping Two Numbers Using Two Variables In C - SWAPTWONUMBERS.C */

#include<stdio.h>
#include<conio.h>
void main()
{
    int num1, num2 ;
    clrscr() ;
    printf("Enter two numbers : ") ;
    scanf("%d %d", &num1, &num2) ;
    printf("\nBefore swapping : \n\n") ;
    printf("num1= %d \t num2 = %d", num1, num2) ;

    /* Swapping Two Numbers Logic */
    num1 = num1 + num2 ;
    num2 = num1 - num2 ;
    num1 = num1 - num2 ;
    printf("\n\nAfter swapping : \n\n") ;
    printf("num1 = %d \t num2 = %d", num1, num2) ;
    getch() ;
}

C Program To Swap Two Numbers Output

After you compile and run the above program your C compiler asks you to enter two numbers, then it will show output before swapping and after swapping two numbers like below expected output.

Enter two numbers : 10 20

Before swapping :
num1 = 10 num2 = 20

After swapping :
num1 = 20 num2 = 10

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables