递归实现ab
#include<iostream>
using namespace std;
const int N = 5;
double fun(double a,double b){
return a==1?b:b+fun(a-1,b);
}
void main(){
double a[N] = {10,9,8,7,6};
double b[N] = {5,6,7,8,9};
int i = 0;
while(i < 5){
cout << a[i] << b[i] << "result:" << fun(a[i],b[i]) << endl;
i++;
}
}
测试结果:
posted on 2020-12-27 18:31 HatTrickMaster 阅读(35) 评论(0) 编辑 收藏 举报