;

C Program To Swap Two Numbers using a Temporary variable


Tutorialsrack 03/11/2019 C

In this C program, we will learn how to write a program to swap two numbers using a temporary variable.

Here is the code of the program to swap two numbers using a temporary variable.

Code - C Program To Swap Two Numbers using a Temporary variable
//C Program To Swap Two Number using Temporary variable
#include <stdio.h>

 void main()
 {
    int a = 5, b = 10, temp;
    printf("Number Before swap a= %d and b= %d", a, b);
    //swapping Logic
    temp = a;
    a = b;
    b = temp;
    printf("\nNumber After swapping a= %d and b= %d", a, b); 
 }
Output

Number Before swap a= 5 and b= 10
Number After swapping a= 10 and b= 5
--------------------------------
Process exited after 0.04124 seconds with return value 37
Press any key to continue . . .


Related Posts



Comments

Recent Posts
Tags