;

C Program to Swap Two Numbers using * & / operator


Tutorialsrack 03/11/2019 C

In this C program, we will learn how to write a program to swap two numbers using * & / operator.

Here is the code of the program to swap two numbers using * & / operator.

Code - C Program to Swap Two Numbers using * & / operator
//C Program to Swap Two Number using * & / operator
#include <stdio.h>

void main()
{
    int a = 5, b = 10, temp;
    printf("Number Before swap a= %d and b= %d", a, b);
    //swapping Logic
    a = a * b; //Here, a=50 (5*10)
    b = a / b; //Here, b=5  (50/10)
    a = a / b; //Here, a=10 (50/5)
    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.04015 seconds with return value 37
Press any key to continue . . .


Related Posts



Comments

Recent Posts
Tags