floor -- Round Down a Floating-Point Number

SYNOPSIS

 #include <math.h>

 double floor(double y);
 

DESCRIPTION

floor rounds a real number down to the next smaller integral real number.

RETURN VALUE

floor accepts a floating-point argument y and rounds it down to the next smaller integer expressed as a floating-point number.

IMPLEMENTATION

floor is implemented as a built-in function unless it is undefined by an #undef statement.

EXAMPLE

  #include <math.h>
  #include <stdio.h>

  int moda, modb, df;
  double score, rank;

  main()
  {
     puts("Enter two integers: ");
     scanf("%d %d", &moda, &modb);

     puts("Enter an integer divisor: ");
     scanf("%d",&df);

        /* Add the two numbers, divide by the given divisor, */
        /*  and then round up to the closest integer less    */
        /*  than the result.                                 */
     score = ( moda + modb);
     score /= df;
     rank = floor(score);

        /* Print the rounded result (its "floor"ed value).   */
     printf("The floor of (%d + %d)/ %d = %fn",moda,modb,df,rank);
  }

 

RELATED FUNCTIONS

ceil

SEE ALSO

Mathematical Functions

Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.