相关疑难解决方法(0)

了解啤酒瓶示例中的递归

我自己在C中练习递归,我在网上找到了这个例子.但有一件事我不明白.

void singSongFor(int numberOfBottles)
{
if (numberOfBottles == 0) {
    printf("There are simply no more bottles of beer on the wall.\n\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\n",
           oneFewer);
    singSongFor(oneFewer); // This function calls itself!

    // Print a message just before the function ends
    printf("Put a bottle in the recycling, %d empty …
Run Code Online (Sandbox Code Playgroud)

c recursion procedural

5
推荐指数
2
解决办法
462
查看次数

标签 统计

c ×1

procedural ×1

recursion ×1