logo

C++ の Ceil 関数と Floor 関数

数学とコンピューターサイエンスでは、 Floor() 関数と ceil() 関数 で定義されている ヘッダー ファイルでは、実数を先行する最大の整数または後続の最小の整数にそれぞれマップします。

C++ フロア() 関数

Floor() 関数は、引数として渡された値以下の最大の整数を返します (つまり、最も近い整数を切り捨てます)。



Java例外処理

フロア() 構文

double floor (double x );>

ここで、x は浮動小数点値です。 x 以下の最大の整数を返します。

いくつかの浮動小数点値の下限の例:

Input : 2.5 Output : 2 Input : -2.1 Output : -3>

CPP








// C++ program to demonstrate floor function> #include> #include> using> namespace> std;> // Driver function> int> main()> {> >// using floor function which return> >// floor of input value> >cout <<>'Floor of 2.3 is : '> <<>floor>(2.3) << endl;> >cout <<>'Floor of -2.3 is : '> <<>floor>(-2.3) << endl;> >return> 0;> }>

>

>

出力

TCPとUDPの比較
Floor of 2.3 is : 2 Floor of -2.3 is : -3>

C++ ceil() 関数

C++ の ceil() 関数は、引数として渡された値以上の最小の整数を返します (つまり、最も近い整数を切り上げます)。

ceil()の構文

double ceil (double x );>

ここで、x は浮動小数点値です。 x 以上の最小の整数を返します。

いくつかの浮動小数点値の上限の例:

Input : 2.5 Output : 3 Input : -2.1 Output : -2>

C++




// C++ program to demonstrate ceil function> #include> #include> using> namespace> std;> // Driver function> int> main()> {> >// using ceil function which return> >// floor of input value> >cout <<>' Ceil of 2.3 is : '> <<>ceil>(2.3) << endl;> >cout <<>' Ceil of -2.3 is : '> <<>ceil>(-2.3) << endl;> >return> 0;> }>

>

>

出力

autocadストレッチコマンド
 Ceil of 2.3 is : 3 Ceil of -2.3 is : -2>

時間計算量: ○(1)
補助スペース: ○(1)

C++におけるceil()とfloor()の違い

ceil() 関数と Floor() 関数の違いを表形式で見てみましょう。

はい・いいえ

ceil() 関数

フロア()関数

1.

n 以上の最小の整数値 n を返すために使用されます。 これは、n 以下の最大の整数値 n を返すために使用されます。

2.

n を上向きに丸めます。 n を小数点以下に丸めます。

3.

その構文は次のとおりです。

data_type セル (n) ;

その構文は次のとおりです。

data_type フロア (n);