由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - how to get division and reminder in one operation?
相关主题
delete[]的设计很不好operator执行顺序
c的小问题size不固定的struct怎么定义呀?
C语言的变量都一定要放在stack上吗?求题目
这里的牛人很多,都读过标准吗求题目
写一个C语言的编译器大概要多少时间?C++ Q93 - Q95 (转载)
C问题,被64bit iPhone搞晕了一个哈希表问题
为什么在overloading中,friend <<不能读取private值呢?Check if the sum of two integers in an integer array eqauls to the given number
C++: operator new 为啥要是 static的, 不是有啥影响?面试题 -算法?
相关话题的讨论汇总
话题: reminder话题: division话题: operation话题: get话题: n1
进入Programming版参与讨论
1 (共1页)
c**u
发帖数: 2230
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?
t****t
发帖数: 6806
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?

k****f
发帖数: 3794
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?

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

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

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

【在 c**u 的大作中提到】
: I think using one "execution" (or one run) is more appropriate. any ideas?
1 (共1页)
进入Programming版参与讨论
相关主题
面试题 -算法?写一个C语言的编译器大概要多少时间?
两道M软件大公司的最新面世算法题 (转载)C问题,被64bit iPhone搞晕了
ambiguous operators in c++为什么在overloading中,friend <<不能读取private值呢?
fork(): why both if and else are executed?C++: operator new 为啥要是 static的, 不是有啥影响?
delete[]的设计很不好operator执行顺序
c的小问题size不固定的struct怎么定义呀?
C语言的变量都一定要放在stack上吗?求题目
这里的牛人很多,都读过标准吗求题目
相关话题的讨论汇总
话题: reminder话题: division话题: operation话题: get话题: n1