Question: 1 . Write and test a C + + program to implement the following algorithms: GCD computation using iterative and recursive algorithms Tower of Hanoi
Write and test a C program to implement the following algorithms:
GCD computation using iterative and recursive algorithms
Tower of Hanoi displaying the order of moving disks using recursive algorithm.
The pseudocode for algorithms are given as below:
GCDIterativea b
While b
temp a mod b
a b
b temp
return a
GCDRecursivea b
If b
Return a
Else
Return GCDRecursiveb a mod b
TowerOfHanoiN From, To Via
From, To Via are string variables, N is integer
If N
Return
TowerOfHanoiN From, Via, To
Print Move Disk n from From To To
TowerOfHanoiN Via, To From
In all these functions, introduce a runtime for computations of runtime.
Initialize the runtime for each one to in the beginning of main.
Then increment by relevant runtime in each of the three functions
From the main, call each of the functions with suitable inputs.
For GCD a and b must be user inputs
For the Tower problem, send names of tower say A B C or tower tower tower and number of disks as user inputs this must be done either at the time of calling the function or prior to it
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
