0% found this document useful (0 votes)
14 views3 pages

Innovative Activity Report Format

Uploaded by

varunpunnal59
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Innovative Activity Report Format

Uploaded by

varunpunnal59
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

YESHWANTRAO CHAVAN COLLEGE OF ENGINEERING, NAGPUR

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


Session: 2024-2025

Innovative Activity 2- Project-Based Learning


Subject: Data Structures

Name: 1) Vyankatesh Punnal (170)


2) Sujal Belkhode (179)

Title: “Tower Of Hanoi Puzzle"

Theory:

Identify three pegs: source (A), auxiliary (B), and destination (C).Initialize a variable
n to the number of disks to be moved. If n is 1, move the top disk from the source peg
(A) to the destination peg (C) directly. Otherwise, follow these steps recursively: a.
Move the top n-1 disks from the source peg (A) to the auxiliary peg (B) using the
destination peg (C) as a temporary peg. b. Move the remaining disk from the source
peg (A) to the destination peg (C). c. Move the n-1 disks from the auxiliary peg (B) to
the destination peg (C) using the source peg (A) as a temporary peg. Repeat the above
steps until all disks are moved from the source peg (A) to the destination peg (C).The
algorithm follows the principles of divide and conquer, moving smaller subproblems
first and leveraging recursion to solve larger instances of the problem. This algorithm
ensures that the Tower of Hanoi puzzle is solved efficiently with the least number of
moves while adhering to the rules of the game.
Code:

#include <stdio.h>
void towerOfHanoi(int n, char source, char auxiliary, char destination)
{
if (n == 1)
{
printf("Move disk 1 from %c to %c\n", source, destination);
return;
}
towerOfHanoi(n - 1, source, destination, auxiliary);
printf("Move disk %d from %c to %c\n", n, source, destination);
towerOfHanoi(n - 1, auxiliary, source, destination);
}
int main()
{
int n;
printf("Enter the number of disks: ");
scanf("%d", &n);
towerOfHanoi(n, 'A', 'B', 'C');
return 0;
}
Output:

Conclusion:

The Tower of Hanoi is a simple mathematical puzzle often employed for the assessment of problem-
solving and in the evaluation of frontal lobe deficits. The task allows researchers to observe the
participant's moves and problem-solving ability, which reflect the individual's ability to solve simple
real-world problems

You might also like