Exemplo n.º 1
0
int main(int argc, const char * argv[])
{
    singSongFor(4);
    
    return 0;
    
}
Exemplo n.º 2
0
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);
        
        printf("Put a bottle in the recycling, %d empty bottles in the bin.\n", numberOfBottles);
    }
}
Exemplo n.º 3
0
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); //RECURSION!
        
        // After recursion executions have no more left, code resumes here at 1, each cycle counting back toward the given int in main for singSongFor();
        printf("Put a bottle in the recycling, %d empty bottles in the bin. \n", numberOfBottles);
    }
}
Exemplo n.º 4
0
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", oneFewer);
        
        singSongFor(oneFewer);
        
        //Print the message just before the function ends
        printf("Put a bottle in the recycling, %d empty bottles of in the bin.\n", numberOfBottles);
               
        
    }
}