Saturday, July 28, 2018

Example of swap between two floating number

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:

No comments:

Post a Comment

C program for find square value

This is an example of how to find square value of a number using function.  #include<stdio.h> float square ( float x ); int ma...