div ライブラリ関数

2 つの整数値の商と剰余を計算する

div_t div( int numer, int denom );

サンプルです。

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

int main()
{
        int x,y;
        div_t result;   /* div_t 構造体 */

        x = 10;
        y = 5;

        printf( "%d ÷ %d = ", x, y );
        result = div( x, y );
        printf( "%d 余り %d\n", result.quot, result.rem );

        return 0;
}

トップページ