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
Related Topic: Write a C Program to Swap Numbers Using Temporary Variable?