C++算法六:递归

  • 递归的神,迭代的是人
  • 自己调用自己
  • 可以使用递归都可使用迭代(循环),递归在计算中需要暂存消耗内存,计算速度慢,优点清楚容易理解
#include<iostream>
using namespace std;
void doA()
{
    cout<<"hello"<<endl;
    doA();
}
int jiecheng(int n)
{
    if (n =0)
        return 1;
    else
        return n*jiecheng(n-1);
}
int main()
{
    //doA();
    int    result = jiecheng(5);
    cout<<result;
    return 0;
}



猜你喜欢

转载自blog.csdn.net/ziyouyi111/article/details/80355488
今日推荐