黑马程序员技术交流社区
标题:
分享一道很有意思的递归案例
[打印本页]
作者:
vyqrvwgf
时间:
2015-11-4 23:27
标题:
分享一道很有意思的递归案例
#import <Foundation/Foundation.h>
void singTheSong(int numberOfBottles){
if(numberOfBottles==0){
printf("There are simply no more bottles of beer on the wall.\n");
}else{
printf("%d bottles of beer on the wall. %d bottles of beer.\n",numberOfBottles,numberOfBottles);
int oneFewer = numberOfBottles-1;
printf("Take one down,pass it around, %d bottles of beer on the wall.\n",oneFewer);
singTheSong(oneFewer);
printf("Put a bottle in the recycling, %d empty bottles in the bing.\n",numberOfBottles);
}
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
singTheSong(99);
}
return 0;
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2