请问在C++中有哪些整除的方法

SingoHuxi 2003-05-29 07:10:41
请问在C++中有哪些整除的方法?当然也可以用数学函数。
...全文
649 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
煜知搬砖者 2003-05-29
  • 打赏
  • 举报
回复
有道理,
ac669 2003-05-29
  • 打赏
  • 举报
回复
不明白楼主的意思。
同意steedhorse(晨星)
idontlikenickname 2003-05-29
  • 打赏
  • 举报
回复
啊?! Weird~~~
搜肠刮肚,补充一下,函数方法:
div_t div(int, int);
ldiv_t ldiv(long, long);

例子:
/* DIV.C: 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>

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

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




/* LDIV.C: This program takes two long integers
* as command-line arguments and displays the
* results of the integer division.
*/

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

void main( void )
{
long x = 5149627, y = 234879;
ldiv_t div_result;

div_result = ldiv( x, y );
printf( "For %ld / %ld, the quotient is ", x, y );
printf( "%ld, and the remainder is %ld\n",
div_result.quot, div_result.rem );
}

Output:
For 5149627 / 234879, the quotient is 21, and the remainder is 217168


晨星 2003-05-29
  • 打赏
  • 举报
回复
什么意思。
整除就是“/”啊,只要左右操作数都是整数。

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧