top of page
Search

Write a C Program to Swap Number without Using Temporary Variables?




Write a C Program to Swap Number without Using Temporary Variables?

#include <stdio.h>

int main()

{

double firstNumber, secondNumber;

printf("Enter first number: ");

scanf("%lf", &firstNumber);

printf("Enter second number: ");

scanf("%lf",&secondNumber); // Swapping process

firstNumber = firstNumber - secondNumber;

secondNumber = firstNumber + secondNumber;

firstNumber = secondNumber - firstNumber;

printf("After swapping, First Number = %.2lf\n", firstNumber);

printf("After swapping, Second Number = %.2lf", secondNumber);

return 0;

}


Output:

Enter first number: 10.25

Enter second number: -12.5

After swapping, First Number = -12.50

After swapping, Second Number = 10.25


For Video Explanations Check Out Our Playlist on Youtube HERE.


11 views
bottom of page