In this program, i used temporary variables.
fnum , snum and twonum are variables in this program.In below the program twonum is assigned the value of fnum .
Then the value of fnum is assigned to snum .Finally , the twonum is assigned to snum which completes the swapping process.
#include <stdio.h>
int main()
{
double fnum, snum, twonum;
printf("Enter first number: ");
scanf("%lf", &fnum);
printf("Enter second number: ");
scanf("%lf",&snum);
twonum = fnum;
fnum = snum;
snum = twonum;
printf("\nAfter swapping, fnum = %.2lf\n", fnum);
printf("After swapping, snum = %.2lf", snum);
return 0;
}
Output:
fnum , snum and twonum are variables in this program.In below the program twonum is assigned the value of fnum .
Then the value of fnum is assigned to snum .Finally , the twonum is assigned to snum which completes the swapping process.
#include <stdio.h>
int main()
{
double fnum, snum, twonum;
printf("Enter first number: ");
scanf("%lf", &fnum);
printf("Enter second number: ");
scanf("%lf",&snum);
twonum = fnum;
fnum = snum;
snum = twonum;
printf("\nAfter swapping, fnum = %.2lf\n", fnum);
printf("After swapping, snum = %.2lf", snum);
return 0;
}
Output:

No comments:
Post a Comment