当前位置:  开发笔记 > 编程语言 > 正文

打印程序,请说明输出

如何解决《打印程序,请说明输出》经验,为你挑选了1个好方法。



1> 小智..:

最后,您会看到调用myPrint它们发生的顺序.

这是查看每次递归调用期间发生的事情的一种方法.

myPrint(4)
  printf("%d", n/2)  // Prints 2 because 4/2 = 2
  myPrint(n - 1) // Calls myPrint(3)
    printf("%d", n/2)  // Prints 1 because 3/2 = 1
    myPrint(n - 1) // Calls myPrint(2)
      printf("%d", n/2)  // Prints 1 because 2/2 = 1
      myPrint(n - 1) // Calls myPrint(1)
        printf("%d", n/2)  // Prints 0 because 1/2 = 0
        myPrint(n - 1) // Calls myPrint(0)
          printf("%d", n/2)  // Prints 0 because 0/2 = 0
          // Does not execute if statement
          printf("%d", n);  // Prints 0 because n = 0 at this call
        printf("%d", n);  // Prints 1 because n = 1 at this call
      printf("%d", n);  // Prints 2 because n = 2 at this call
    printf("%d", n);  // Prints 3 because n = 3 at this call
  printf("%d", n);  // Prints 4 because n = 4 at this call

推荐阅读
刘美娥94662
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有