问题

( 9 )下面的函数利用递归实现了求 1+2+3+ …… +n 的功能:

int sum ( int n ) {

if ( n==0 )

return 0;

else

return n+sum ( n-1 ) ;

}

在执行 sum ( 10 )的过程中,递归调用 sum 函数的次数是【 9 】 。

参考答案
您可能感兴趣的试题
  • ( 10 )非成员函数应该声明为类【 10 】函数才能访问该类的私有成员。
  • ( 11 )有如下程序:#includeusing namespace std;class Monitor{public:Monitor ( char t ) : type ( t
  • ( 12 )有如下程序:#include using namespace stdclass Animal{public:virtual char* getType () const
  • ( 13 )补充完整下面的类定义:const double PI=3 .14;class Circle{ // 圆形物体的抽象基类protected:double r; // 半径public:Cir
  • ( 14 )补充完整下面的类定义:class XCH{char* a;public:XCH ( char* as ) { // 构造函数a=new char[strlen ( aa ) +1];str
  • ( 15 )补充完整下面的模板定义:template //Type 为类型参数class Xtwo{ // 由两个 Type 类型的数据成员构成的模板类Type a;Type