黑马程序员技术交流社区

标题: 分享一道很有意思的递归案例 [打印本页]

作者: vyqrvwgf    时间: 2015-11-4 23:27
标题: 分享一道很有意思的递归案例
  1. #import <Foundation/Foundation.h>
  2. void singTheSong(int numberOfBottles){
  3.     if(numberOfBottles==0){
  4.         printf("There are simply no more bottles of beer on the wall.\n");
  5.     }else{
  6.         printf("%d bottles of beer on the wall. %d bottles of beer.\n",numberOfBottles,numberOfBottles);
  7.         int oneFewer = numberOfBottles-1;
  8.         printf("Take one down,pass it around, %d bottles of beer on the wall.\n",oneFewer);
  9.         singTheSong(oneFewer);
  10.         printf("Put a bottle in the recycling, %d empty bottles in the bing.\n",numberOfBottles);
  11.     }
  12. }
  13. int main(int argc, const char * argv[]) {
  14.     @autoreleasepool {
  15.         singTheSong(99);
  16.     }
  17.     return 0;
  18. }
复制代码






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2