目录
AC: 9 / 9
用时:1 h 4 min
递归专题。
7-1 递归 递推
#include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 110; int n, f1, a, b; int func(int x) { if(x == 1) return f1; return a * func(x - 1) + b; } int main() { while(scanf("%d%d%d%d", &n, &f1, &a, &b) != EOF) { cout << func(n) << endl; } return 0; }注意,输入内容中没有给出数据组数或者结束输入的标志。
7-2 函数的递归调用
#include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 110; int n; int func(int x) { if(x == 0 || x == 1) return 1; return x * func(x - 1); } int main() { cin >> n; if(n < 0) printf("%d<0,no value!no value!", n); else printf("%d!=%d", n, func(n)); return 0; }n < 0时那个逗号是全角符号,建议直接复制粘贴。
7-3 A010 递归练习1
#includ

本文提供了一系列递归编程的练习,包括递推公式应用、阶乘计算、递归函数设计以及Fibonacci数列的计算。此外,还涉及了将整数转换为字符串的方法以及简单的数据集合并操作。这些例子展示了递归在解决各种问题中的应用。



最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



