# 算法设计二第三周-递归函数

1、第一题

5

7

5, 4+1, 3+2, 3+1+1, 2+2+1, 2+1+1+1, 1+1+1+1+1

#include<iostream>
using namespace std;

int fun(int x,int y){
if(x<y) return fun(x,x);
if(x==0||y==1) return 1;
return fun(x,y-1)+fun(x-y,y);
}
int main(){
int n;
while(cin>>n){
cout<<fun(n,n)<<endl;
}
return 0;
}

# include

using namespace std;
int fun(int n,int m)
{
if(n < 1|| m < 1)
return 0;
if(n == 1||m == 1)
return 1;
if(n < m)
return fun(n,n);
if(n == m)
return fun(n,m-1)+1;
if(n > m)
return fun(n,m-1) + fun(n-m,m);
}
int main(void)
{
int n=1,b[51],i=0;
char y;
do
{
scanf(“%d”,&b[i++]);
if(b[i]>50||b[i]<=0)
exit(0);
} while((y=getchar()) != ‘\n’);
for(int j = 0;j

#include<iostream>
#include <cstdio>
using namespace std;
int jishu(int a,int b){
int a1 = a;
a = a*3+1;
b= a;
printf("%d*3+1=%d\n",a1,a);
return b;
};
int oushu(int a,int b){
int a1 = a;
a = a/2;
b= a;
printf("%d/2=%d\n",a1,a);
return b;
};
int main(){
int a,b;
scanf("%d",&a);
while(b !=1) {
if (a==1)
{
printf("End");
break;
};
if(a%2==0)
{
oushu(a,b);
b =  oushu(a,b);
cout << b;
}
else
{
jishu(a,b);
b=jishu(a,b);
}
};
return 0;
}