Compartilhar via


div

Calcula o quociente e o restante dos dois valores inteiros.

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

Parâmetros

  • numer
    O numerador.

  • denom
    O denominador.

Valor de retorno

div chamado com argumentos de tipo int Retorna uma estrutura de tipo div_t, que englobam o quociente e o restante. O valor retornado da sobrecarga com argumentos de tipo long é ldiv_t. Ambos os div_t e ldiv_t são definidos em STDLIB.H.

Comentários

The div função divide numer Por denom, o quociente e o restante de computação. The div_t structure contains intquot, the quotient, and intrem, the remainder.O sinal do quociente é o mesmo que o quociente de matemático.O valor absoluto é o maior inteiro menor do que o valor absoluto do quociente de matemático.Se o denominador é 0, o programa termina com uma mensagem de erro.

A sobrecarga levar argumentos do tipo long só está disponível para código C++. The return type ldiv_t contains the members longquot and longrem, which have the same meanings as the members of div_t.

Requisitos

Rotina

Cabeçalho necessário

div

<stdlib.h>

Para obter informações adicionais compatibilidade, consulte Compatibilidade na introdução.

Exemplo

// 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 );
}

x is 876, y is 13 The quotient is 67, and the remainder is 5

Equivalente do NET Framework

Não aplicável. Para telefonar a função C padrão, use PInvoke. Para obter mais informações, consulte Exemplos de invocação de plataforma.

Consulte também

Referência

Suporte de ponto flutuante

ldiv