Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

C stdlib div() 函数

❮ C stdlib 库


示例

执行除法并显示结果

int a = 31;
int b = 10;
div_t result = div(a, b);

printf("%d / %d = %d \n", a, b, result.quot);
printf("Remainder: %d \n", result.rem);
自己尝试 »

定义和用法

div() 函数执行整数除法并返回包含商和余数的结构。

div() 函数在 <stdlib.h> 头文件中定义。

该函数还有两个变体:ldiv() 用于 long int 参数,lldiv() 用于 long long int 参数。


语法

以下之一

div(int dividend, int divisor);
ldiv(long int dividend, long int divisor);
lldiv(long long int dividend, long long int divisor);

参数值

参数 描述
被除数 必需。除法的被除数。
除数 必需。除法的除数。

技术细节

返回值 div() - 一个具有 int 成员的 div_t 结构。
ldiv() - 一个具有 long int 成员的 ldiv_t 结构。
lldiv() - 一个具有 long long int 成员的 lldiv_t 结构。
返回的结构有两个成员
  quot - 表示除法的商。
  rem - 表示除法的余数。

❮ C stdlib 库

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.