Question

Fibonaco for its rets ing terms, a) Write a warruse function fibonacci(n) that calculatus 0, 1, 1, 2, 3, 5, 8, 13, 21,... (n)
Untents are Exercises 209 Fig. 5.23 Towers of Hanoi for the case with four disks. b) Move the last disk (the largest) from pe

write in c programming language .

question 5.36
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the answer..

CODE:

#include <stdio.h>

void toh(int n, int from_peg, int to_peg, int temp_peg)
{
   if (n == 1)
   {
       printf("\n %d -> %d", from_peg, to_peg);
       return;
   }
   toh(n-1, from_peg, temp_peg, to_peg);
   printf("\n %d -> %d", from_peg, to_peg);
   toh(n-1, temp_peg, to_peg, from_peg);
}

int main()
{
   int n = 3;
   toh(n, 1, 3, 2);
   return 0;
}

OUTPUT:

toh.c i #include <stdio.h> void toh(int n, int from_peg, int to_peg, int temp_peg) C:\Program Files (x86) Dev-Cpp\ConsolePaus

If you have any doubts please COMMENT..

If you understand the answer please give THUMBS UP...

Add a comment
Know the answer?
Add Answer to:
write in c programming language . question 5.36 Fibonaco for its rets ing terms, a) Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Describe a recursive algorithm for solving the Towers of Hanoi puzzle for an arbitrary n (see...

    Describe a recursive algorithm for solving the Towers of Hanoi puzzle for an arbitrary n (see Creativity Exercise C-5.16 for more details). C-5.16 In the Towers of Hanoi puzzle, we are given a platform with three pegs, a, b, and c, sticking out of it. On peg a is a stack of n disks, each larger than the next, so that the smallest is on the top and the largest is on the bottom. The puzzle is to move all...

  • Assignment 2 In this assignment, you will write two short programs to solve problems using recursion....

    Assignment 2 In this assignment, you will write two short programs to solve problems using recursion. 1. Initial Setup Log in to Unix. Run the setup script for Assignment 2 by typing: setup 2 2. Towers of Hanoi Legend has it that in a temple in the Far East, priests are attempting to move a stack of disks from one peg to another. The initial stack had 64 disks threaded onto one peg and arranged from bottom to top by...

  • Write the recursive MIPS code (with abundant explanatory comments) for the Tower of Hanoi problem of...

    Write the recursive MIPS code (with abundant explanatory comments) for the Tower of Hanoi problem of transferring a stack of N disks (smaller sized disks stacked over the larger sized ones) from a source peg to a destination peg via a third (temporary rest peg) under the constraints: 1. Only one disk is moved at a time from one peg to another 2. At no time, a larger disk will sit on a smaller one.

  • Therefore, getx-log,n from 2on. So the time complexity of this loop is O logn). Eliminate low...

    Therefore, getx-log,n from 2on. So the time complexity of this loop is O logn). Eliminate low order terms 26 00:01 00:01 Homework #7 Homework #7 - 7.1 Design the algorithm of Towers of Hanoi. . Source peg, Destination peg, Auxlary peg s k disks on the source peg, a bigger disk can never be on top of a smaler dsk : Need to move al k disks to the destination peg using the auxillary peg, without ever keeping a bigger...

  • Part A [50] in c++ A toy that many children play with is a base with...

    Part A [50] in c++ A toy that many children play with is a base with three pegs and five disks of different diameters. The disks begin on one peg, with the largest disk on the bottom and the other four disks added on in order of size. The idea is to move the disks from the peg they are on to another peg by moving only one disk at a time and without ever putting a larger disk on...

  • language use : c++ Correct Tower application to move the disks from the pin on the...

    language use : c++ Correct Tower application to move the disks from the pin on the left to the pin on the right. Hint: draw the motion of th disks for a small set "say three" and walk your way through the recursion. #include <iostream> using namespace std; void towers(int,char,char,char); int main() int num; cout << "Number of disks: "; cin >> num; cout << "Sequences begin here \n"; towers(num, 'A', 'B! "C"); return 0; void towers(int num, char frompeg,...

  • Write a function in prolog pragramming languaged named, "ionah", that takes a single number as input...

    Write a function in prolog pragramming languaged named, "ionah", that takes a single number as input and prints out the solution to the inverted disk problem for that many disks.  This is the problem of moving a stack of k disks of increasing size from bottom to top, from the first peg to the third peg with another peg that may be used as well, subject to the condition that a smaller disk is never put on top of a larger...

  • Write a Python program that implements the Towers of Hanoi, using the recursive algorithm discussed in...

    Write a Python program that implements the Towers of Hanoi, using the recursive algorithm discussed in class. Use command-line arguments to pass parameters to the program - spring% python towersOfHanoi.py USAGE: towersOfHanoi.py <# rings> <FROM peg> <TO peg> spring% python towersOfHanoi.py 4 1 3 Move disk from peg 1 to peg 2 Move disk from peg 1 to peg 3 Move disk from peg 2 to peg 3 Move disk from peg 1 to peg 2 Move disk from peg...

  • (IN JAVA) Legend says that this problem was originated either by Buddhist monks, Brahman priests, or...

    (IN JAVA) Legend says that this problem was originated either by Buddhist monks, Brahman priests, or the guardians of a Vietnamese temple, take your pick. In each case, they believed that if the puzzle could be solved using 64 disks, the world would end. Since the number of moves required to solve the Tower of Hanoi problem using “n” disks is 2n - 1, and assuming that each move would take roughly one second, then moving 64 disks from one...

  • Towers of Hanoi (15 points) Given: n disks, all of different sizes the size of the...

    Towers of Hanoi (15 points) Given: n disks, all of different sizes the size of the ith disk is į .3 pegs - A, B, C the number of pegs might change in a future version of the game Inally, all the disks are stacked on peg A Requirement: Never place a larger disk on top of a smaller disk (disk 5 is larger than disk 4, etc.) Objective: Move the disks from peg A to peg C Input: n,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT