/* div example */
#include <stdio.h>
#include <stdlib.h>
int main ()
{
div_t divresult;
divresult = div (38,5);
printf ("38 div 5 => %d, remainder %d.\n", divresult.quot, divresult.rem);
return 0;
}
Вывод:
38 div 5 => 7, remainder 3.
EDIT:
В спецификации C указано:
7.20 Общие утилиты
The types declared are size_t and wchar_t (both described in 7.17),
div_t
which is a structure type that is the type of the value returned by the div function,
ldiv_t
which is a structure type that is the type of the value returned by the ldiv function, and
lldiv_t
which is a structure type that is the type of the value returned by the lldiv function.
... но он не говорит, что такое определение div_t.
Ответ 2
Да, существует стандартная функция div() (и ldiv, а может быть даже lldiv), которая делает это.