Udostępnij za pośrednictwem


DIV

Oblicza iloraz, a reszta z dwóch wartości całkowitych.

div_t div( 
   int numer,
   int denom 
);
ldiv_t div(
   long numer,
   long denom
);

Parametry

  • numer
    Licznik.

  • denom
    Mianownik.

Wartość zwracana

divwywołana z argumentami typu int zwraca struktury typu div_t, obejmujący iloraz, a reszta.Wartość zwracana przeciążenie z argumentami typu long jest ldiv_t.Obie div_t i ldiv_t są zdefiniowane w STDLIB.H.

Uwagi

div Działać dzieli numer przez denom, computing iloraz, a reszta.The div_t structure contains intquot, the quotient, and intrem, the remainder.Znak iloraz jest taka sama jak iloraz matematycznych.Jego wartość bezwzględna jest największą liczbą całkowitą mniejszą niż bezwzględna wartość ilorazu matematycznych.Jeżeli dzielnik wynosi 0, program zakończy się komunikat o błędzie.

Przeciążenie, uwzględniając argumenty typu long jest dostępna tylko dla kodu C++.Zwracany typ ldiv_t zawiera członków longquot i longrem, które mają tych samych znaczeń jako członkowie div_t.

Wymagania

Rozpoczęto wykonywanie procedury

Wymaganego nagłówka

div

<stdlib.h>

Aby uzyskać dodatkowe informacje o zgodności, zobacz zgodności we wprowadzeniu.

Przykład

// crt_div.c
// arguments: 876 13

// This example takes two integers as command-line
// arguments and displays the results of the integer
// division. This program accepts two arguments on the
// command line following the program name, then calls
// div to divide the first argument by the second.
// Finally, it prints the structure members quot and rem.
//

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

int main( int argc, char *argv[] )
{
   int x,y;
   div_t div_result;

   x = atoi( argv[1] );
   y = atoi( argv[2] );

   printf( "x is %d, y is %d\n", x, y );
   div_result = div( x, y );
   printf( "The quotient is %d, and the remainder is %d\n",
           div_result.quot, div_result.rem );
}
  

Odpowiednik w programie .NET Framework

Nie dotyczy. Aby wywołać standardowych funkcji C, należy użyć PInvoke. Aby uzyskać więcej informacji, zobacz Przykłady wywołać platformy.

Zobacz też

Informacje

Wsparcie zmiennoprzecinkowe

ldiv