## THIS USER ASKED ๐

**Write code to complete DoublePennies()’s base case. Sample output for below program:Number of pennies after 10 days: 1024#include // Returns number of pennies if pennies are doubled numDays timeslong long DoublePennies(long long numPennies, int numDays){long long totalPennies = 0;/* Your solution goes here */else {totalPennies = DoublePennies((numPennies * 2), numDays – 1);}return totalPennies;}// Program computes pennies if you have 1 penny today,// 2 pennies after one day, 4 after two days, and so onint main(void) {long long startingPennies = 0;int userDays = 0;startingPennies = 1;userDays = 10;printf(“Number of pennies after %d days: %lldn”, userDays, DoublePennies(startingPennies, userDays));return 0;}**

## THIS IS THE BEST ANSWER ๐

The full code along with outputs and comments are explained below.

Explanation:

#include

// function DoublePennies starts here

// The DoublePennies function returns the number of pennies if the pennies are doubled numDays times

// this is an example of a recursive function that basically calls itself

DoublePennies long long (numPennies long long, int numDays) {

total long totalPennies = 0;

\ here we applied the base case when the number of days is zero then return the number of pennies

if (numDays == 0)

return numPennies;

// if the underlying case is not executed then this other condition will be executed doubling the number of pennies for each consecutive day.

other

{

totalPennies = DoublePennies (numPennies * 2), numDays – 1);

}

TotalPennies back;

}

// driver code starts here

// The program calculates pennies if you have 1 penny today,

// 2 pence after one day, 4 after two days, and so on

int main (null)

{

// start front pennies and number of days

long long bootPennies = 0;

int userDays = 0;

// initial penny input and number of days

startingPennies = 1;

userDays = 10;

// print number of pennies and number of days

printf (“Number of pennies after% d days:% lld n”, userDays, DoublePennies (StartingPennies, userDays));

return 0;

}

Output:

Test 1:

Number of pennies after 10 days:

Test 2:

Number of pennies after 2 days: 4

Test 3:

Number of pennies after 0 days: 1

## Leave a Reply