CPlusPlusThings/practical_exercises/10_day_practice/day2/递归2.cpp
2023-01-02 20:39:00 +08:00

25 lines
369 B
C++

#include<iostream>
using namespace std;
int f(int n, int k);
int main(int argc, char const *argv[])
{
cout<<"请输入n与k"<<endl;
int n,k;
cin>>n;
cin>>k;
cout<<f(n,k)<<endl;
system("pause");
return 0;
}
int f(int n, int k)
{
if ((n==k)||(k==0))
{
return 1;
}
else
{
return f(n-1,k-1)+f(n-1,k);
}
}