C program to Swap two Numbers Without Using Temporary Variable
#include
int main()
{
double a, b; // initialization constant variables
printf("Enter a: "); // user enter number
scanf("%lf", &a); // storing value of user number
printf("Enter b: "); // user enter number
scanf("%lf", &b); // storing value of user number
// Swapping process
a = a - b;
b = a + b;
a = b - a;
printf("After swapping, a = %.2lf\n", a); //swaping
printf("After swapping, b = %.2lf", b); //swaping
return 0;
}
Output
Enter a: 5.25
Enter b: -6.5
After swapping, a = -6.5
After swapping, b = 5.25
Happy Coding
0 comments:
Post a Comment