[Recursion]The Base Case
本人於該blog的全部文章轉移至[Algorithm]The Base Case on Recursion – KKWBlog (kkwtech.com)該網域下,其後此處不進行更新,一律於新站點更新。
#include <iostream>
using namespace std;
int factorial(int n) {
if (n==1) {
return 1;
}
else {
return n * factorial(n-1);
}
}
int main() {
cout << factorial(5);
}
The base case is another name for the exit condition.
“Recursion” that has a exit condition call “Real Recursion”,otherwise it will keep running forerver.
//"exit condition" EX:
if (n==1) {
return 1;
}
Filed under: 演算法 - @ 2021 年 7 月 2 日 下午 3:59