Question: ********C Programming******** Write a recursive function that counts the number of moves that have to be made to transfer a stack of disks from one

********C Programming********

Write a recursive function that counts the number of moves that have to be made to transfer a stack of disks from one pole to another. The following program can be used to calculate the time needed by the priests to transfer the stack of 64 disks. They will move one disk at a time and this will take an average of one second per disk.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include float count_moves(unsigned int nr_of_disks); int main() { unsigned int nr_of_disks = 64; float time_seconds = count_moves(nr_of_disks); /* convert the time in seconds to billions of years */ float time_billion_years = time_seconds / 3600 / 24 / 365 / 1e9; printf("It will take %.1f billion years to move %d disks. ", time_billion_years, nr_of_disks); return 0; } float count_moves(unsigned int nr_of_disks) { /* Write your implementation here */ }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Your program should give the answer in billions of years! 1 billion = 1000 million = 109. And 1 year = 60 * 60 * 24 * 365 seconds! Write your implementation of the count_moves function. The function returns the number of moves needed to transfer the stack of disks. Remember the three steps as explained during the lecture. Use recursion to solve the problem, so no loops or static variables in the recursive function! Also, do not use global variables in your program. The estimated age of the universe is approximately 13.8 billion years. The priests were given the stack of disks at the beginning of time. How many times the current age of the universe will it take for the priests to finish their work?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!