Redian新闻
>
how to get division and reminder in one operation?
avatar
how to get division and reminder in one operation?# Programming - 葵花宝典
c*u
1
image we have two integers N1, N2.
If we want to get the division, we do : division = (int) N1/N2;
if we want to get the reminder, we do: reminder = N1 % N2;
The interview question is how to get both division and reminder in just one
operation, instead of two?
avatar
t*t
2
通常CPU的指令里都是两个一起求的,不过C好象没这说法.好的编译器会自动把这两变成
一个吧.

one

【在 c**u 的大作中提到】
: image we have two integers N1, N2.
: If we want to get the division, we do : division = (int) N1/N2;
: if we want to get the reminder, we do: reminder = N1 % N2;
: The interview question is how to get both division and reminder in just one
: operation, instead of two?

avatar
k*f
3
你得定义什么叫做一个operation
是一个汇编指令?一个函数?一个C语句?

one

【在 c**u 的大作中提到】
: image we have two integers N1, N2.
: If we want to get the division, we do : division = (int) N1/N2;
: if we want to get the reminder, we do: reminder = N1 % N2;
: The interview question is how to get both division and reminder in just one
: operation, instead of two?

avatar
c*u
4
I think using one "execution" (or one run) is more appropriate. any ideas?
avatar
p*o
5
有个叫div/ldiv的非ANSI函数,估计编译器能优化。

【在 t****t 的大作中提到】
: 通常CPU的指令里都是两个一起求的,不过C好象没这说法.好的编译器会自动把这两变成
: 一个吧.
:
: one

avatar
c*u
6
I think using one "execution" (or one run) is more appropriate. any ideas?
avatar
k*f
7
说不清楚就用中文,什么叫做one run

【在 c**u 的大作中提到】
: I think using one "execution" (or one run) is more appropriate. any ideas?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。