update format
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
|
||||
这部分都是一些数学几何计算方面的问题。主要由:
|
||||
|
||||
* 位运算
|
||||
* 随机数
|
||||
* 大数问题
|
||||
|
||||
|
||||
### 字符串转整数
|
||||
|
||||
@@ -146,6 +152,28 @@ int div(const int x, const int y)
|
||||
|
||||
|
||||
|
||||
#### 数值的整数次方
|
||||
|
||||
题目:实现函数double Power(double base, int exponent),求base的exponent次方。
|
||||
|
||||
不需要考虑溢出。
|
||||
|
||||
分析:这是一道看起来很简单的问题。可能有不少的人在看到题目后30秒写出如下的代码:
|
||||
```
|
||||
double Power(double base, int exponent)
|
||||
{
|
||||
double result = 1.0;
|
||||
for(int i = 1; i <= exponent; ++i)
|
||||
result *= base;
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
上面的代码没有考虑 exponent<0的情况。
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#### 求根号2的值
|
||||
|
||||
|
||||
Reference in New Issue
Block a user