lldiv() - long long 型の整数除算の商と剰余の計算

標準

標準/拡張機能 C/C++ 依存項目

z/OS®UNIX
C99
Single UNIX Specification、バージョン 3
C++ TR1 C99

両方

OS/390 V2R10

形式

#include <stdio.h>

long long lldiv(long long numer, long long denom);
コンパイル要件: この関数を使用するには、long long データ型が必要です。long long を使用可能にする方法については、「z/OS XL C/C++ ランゲージ・リファレンス」を参照してください。

機能説明

numerator を denominator で割った商および剰余を計算します。

戻り値

long long quot と剰余 long long rem の両方を含む、lldiv_t 型の構造体を戻します。

値を表せない場合は、未定義な戻り値が戻される結果となります。denominator が 0 の場合は、ゼロ除算例外が起こります。

  /*
     This example uses the
     lldiv() function to calculate the quotients and
     remainders for a set of two dividends and two divisors.
   */
  #define _LONG_LONG 1
  #include <stdio.h>
  #include <stdlib.h>

  int main(void)
  {
     long long  num[2] = {45,-45};
     long long  den[2] = {7,-7};
     lldiv_t ans;   /* lldiv_t is a struct type containing
                       two long long int fields:
                      'quot' stores quotient; 'rem' stores remainder */
     short i,j;

     printf("Results of long division:¥n");
     for (i = 0; i < 2; i++)
        for (j = 0; j < 2; j++)
        {
           ans = lldiv(num[i], den[j]);
           printf("Dividend: %6lld  Divisor: %6lld", num[i], den[j]);
           printf("  Quotient: %6lld  Remainder: %6lld¥n", ans.quot,
                                                             ans.rem);
        }
  }
出力:
  Results of long division:
  Dividend:  45  Divisor:   7  Quotient:   6  Remainder:   3
  Dividend:  45  Divisor:  -7  Quotient:  -6  Remainder:   3
  Dividend: -45  Divisor:   7  Quotient:  -6  Remainder:  -3
  Dividend: -45  Divisor:  -7  Quotient:   6  Remainder:  -3

関連情報