C 库函数 - div()

C 语言教程 · 2019-02-24 10:12:57

描述

C 库函数 div_t div(int numer, int denom)numer(分子)除以 denom(分母)

声明

下面是 div() 函数的声明。

div_t div(int numer, int denom)

参数

  • numer -- 分子。
  • denom -- 分母。

返回值

该函数返回定义在 <cstdlib> 中的结构中的值,该结构有两个成员,如 div_t:int quot; int rem;

实例

下面的实例演示了 div() 函数的用法。

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

int main()
{
   div_t output;

   output = div(27, 4);
   printf("(27/ 4) 的商  = %d\n", output.quot);
   printf("(27/4) 的余数 = %d\n", output.rem);

   output = div(27, 3);
   printf("(27/ 3) 的商 = %d\n", output.quot);
   printf("(27/3) 的余数 = %d\n", output.rem);

   return(0);
}

让我们编译并运行上面的程序,这将产生以下结果:

(27/ 4) 的商 = 6
(27/4) 的余数 = 3
(27/ 3) 的商 = 9
(27/3) 的余数 = 0

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

Remote

Remote

Jason Fried、David Heinemeier Hansson / Crown Business / 2013-10-29 / CAD 26.95

The “work from home” phenomenon is thoroughly explored in this illuminating new book from bestselling 37signals founders Fried and Hansson, who point to the surging trend of employees working from hom......一起来看看 《Remote》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换