[递归]母牛的故事(C语言代码)-Dotcpp编程社区(题目在这)
1 #include <stdio.h> 2 //找到规律最重要,先尽量多写几个例子,找规律 3 int f(int n){ 4 if(n<=3) return n; 5 else{ 6 return f(n-1)+f(n-3); 7 } 8 } 9 10 int main(){ 11 int n; 12 while(scanf("%d",&n)!=EOF){ 13 if(n==0) break; 14 int ans=f(n); 15 printf("%d\n",ans); 16 } 17 return 0; 18 }
标签:规律,递归,int,C语言,Dotcpp,多写,应用,简单 From: https://www.cnblogs.com/messing1758954258/p/17087290.html