C/Math/Round

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Round down value: how to use floor

<source lang="cpp">

  1. include <stdio.h>
  2. include <math.h>

int main () {

 printf ("floor of 3.3 is %.1lf\n", floor ( 3.3 ) );
 printf ("floor of 4.8 is %.1lf\n", floor ( 4.8 ) );
 printf ("floor of -3.3 is %.1lf\n", floor ( -3.3 ) );
 printf ("floor of -4.8 is %.1lf\n", floor ( -4.8 ) );
 return 0;

}


      </source>


Round up a value: ceil

<source lang="cpp">

  1. include <stdio.h>
  2. include <math.h>

int main () {

 printf ("ceil of 3.3 is %.1lf\n", ceil (3.3) );
 printf ("ceil of 4.8 is %.1lf\n", ceil (4.8) );
 printf ("ceil of -3.3 is %.1lf\n", ceil (-3.3) );
 printf ("ceil of -4.8 is %.1lf\n", ceil (-4.8) );
 return 0;

}


      </source>