本文介绍了试图递归地实现幂和阶乘函数。 C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
double power(double base,int exponent);
double factorial(double n);
然后,我完全失去了,我在寻找想法。
$ b好吧,3 ^ 4是3 * 3 * 3 * 3。这是3 * 3 ^ 3。 3 ^ 3是3 * 3 ^ 2。 3 ^ 2是3 * 3 ^ 1。 3 ^ 1为3。5!是5 * 4 * 3 * 2 * 1.是5 * 4!。 4!是4 * 3! 3!是3 * 2! 2!是2 * 1! 1!是1。
这应该给你足够的...。
All ive got so far are the definitions.
double power(double base, int exponent);
double factorial(double n);
And after this i am completely lost and I'm looking for ideas.
解决方案
Well, 3^4 is 3 * 3 * 3 * 3. Which is 3 * 3^3. 3^3 is 3 * 3^2. 3^2 is 3 * 3^1. 3^1 is 3.
5! is 5 * 4 * 3 * 2 * 1. Which is 5 * 4!. 4! is 4 * 3!. 3! is 3 * 2!. 2! is 2 * 1!. 1! is 1.
That should give you enough to be getting on with...
这篇关于试图递归地实现幂和阶乘函数。 C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!