C-standard-library-c-function-div

提供:Dev Guides
移動先:案内検索

Cライブラリ関数-div()

説明

Cライブラリ関数* div_t div(int numer、int denom)は、 numer(分子) denom(分母)*で除算します。

宣言

div()関数の宣言は次のとおりです。

div_t div(int numer, int denom)

パラメーター

  • numer -これは分子です。
  • denom -これは分母です。

戻り値

この関数は、2つのメンバーを持つ<cstdlib>で定義された構造体で値を返します。 div_t:_intの場合; int rem; _

次の例は、div()関数の使用法を示しています。

#include <stdio.h>
#include <stdlib.h>

int main () {
   div_t output;

   output = div(27, 4);
   printf("Quotient part of (27/4) = %d\n", output.quot);
   printf("Remainder part of (27/4) = %d\n", output.rem);

   output = div(27, 3);
   printf("Quotient part of (27/3) = %d\n", output.quot);
   printf("Remainder part of (27/3) = %d\n", output.rem);

   return(0);
}

次の結果を生成する上記のプログラムをコンパイルして実行しましょう-

Quotient part of (27/4) = 6
Remainder part of (27/4) = 3
Quotient part of (27/3) = 9
Remainder part of (27/3) = 0