C programming
Tower of Hanoi
// C recursive function to solve tower of hanoi puzzle
void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 1)
{
printf("\n Move disk 1 from rod %c to rod %c", from_rod, to_rod);
return;
}
towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
printf("\n Move disk %d from rod %c to rod %c", n, from_rod, to_rod);
towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}
int main()
{
int n = 4; // Number of disks
towerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods
return 0;
}
Reference : Wikipedia
OUTPUT :
Move disk 1 from rod A to rod B
Move disk 2 from rod A to rod C
Move disk 1 from rod B to rod C
Move disk 3 from rod A to rod B
Move disk 1 from rod C to rod A
Move disk 2 from rod C to rod B
Move disk 1 from rod A to rod B
Move disk 4 from rod A to rod C
Move disk 1 from rod B to rod C
Move disk 2 from rod B to rod A
Move disk 1 from rod C to rod A
Move disk 3 from rod B to rod C
Move disk 1 from rod A to rod B
Move disk 2 from rod A to rod C
Move disk 1 from rod B to rod C
Tower of Hanoi Program in C
17 January
4
Tower Of Hanoi
Tower of Hanoi Program in C
#include <stdio.h>// C recursive function to solve tower of hanoi puzzle
void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 1)
{
printf("\n Move disk 1 from rod %c to rod %c", from_rod, to_rod);
return;
}
towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
printf("\n Move disk %d from rod %c to rod %c", n, from_rod, to_rod);
towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}
int main()
{
int n = 4; // Number of disks
towerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods
return 0;
}
Reference : Wikipedia
OUTPUT :
Move disk 1 from rod A to rod B
Move disk 2 from rod A to rod C
Move disk 1 from rod B to rod C
Move disk 3 from rod A to rod B
Move disk 1 from rod C to rod A
Move disk 2 from rod C to rod B
Move disk 1 from rod A to rod B
Move disk 4 from rod A to rod C
Move disk 1 from rod B to rod C
Move disk 2 from rod B to rod A
Move disk 1 from rod C to rod A
Move disk 3 from rod B to rod C
Move disk 1 from rod A to rod B
Move disk 2 from rod A to rod C
Move disk 1 from rod B to rod C
Previous article
Next article
Do you realize there's a 12 word phrase you can communicate to your crush... that will induce intense emotions of love and impulsive attractiveness to you deep inside his chest?
ReplyDeleteBecause hidden in these 12 words is a "secret signal" that fuels a man's impulse to love, please and guard you with his entire heart...
=====> 12 Words Who Trigger A Man's Desire Response
This impulse is so hardwired into a man's genetics that it will drive him to try better than before to make your relationship as strong as it can be.
As a matter of fact, fueling this mighty impulse is absolutely essential to getting the best possible relationship with your man that the moment you send your man one of these "Secret Signals"...
...You will immediately notice him expose his soul and mind to you in a way he never experienced before and he'll see you as the only woman in the universe who has ever truly understood him.
We are one of the leading Web Development Company near me in jaipur India. If you are looking for a company that offers penetration testing services in India with affordable prices, then think about us!
ReplyDeleteAvenging Security PVT LTD. Leading Software Development, Digital Marketing, Website & Application Development, Cyber Security Company Jaipur India. If you are looking for a company that provides quality work at affordable prices, then think about us!
CCAS is one of the best CEH training institutes in Jaipur Rajasthan. You can learn training technology ethical hacking, cybersecurity, hands-on training with classroom and only with affordable price. India’s 1st NGO based on Cyber Crime Investigation. This NGO has been established by Experts and Police officers with the view of giving an impetus to technical and legal support to the Cyber Crime affected peoples. CONTACT NOW! Rajasthan Head Branch. 66, Vivek Vihar, New Sanganer Road, Sodala, Jaipur
ReplyDelete|
If you are searching for an Ethical Hackers Academy then you should be join Cyber Crime Awareness Society. Cyber Crime Awareness Society is one of the Best Cyber Security Training In Jaipur. Cyber Crime Awareness Society is IT Consulting Company managed by Ethical Hackers & IT professionals, working with Police Agencies and Cyber Crime Cell of Government in India. It is also backed by a team of Experts working with RAW, CBI, ATS, IB and Cyber Crime Cell with an aim to create India the safest place of internet in the World.
India's 1st NGO based on Cyber Crime Investigation. This NGO has been established by Experts and Police officers with the view of giving an impetus to technical and legal support to the Cyber Crime affected peoples. Cyber Crime Awareness Society is an IT Consulting Company managed by Ethical Hackers & IT professionals, working with Police Agencies and Cyber Crime Cell of Government in India. It is also backed by a team of Experts working with RAW, CBI, ATS, IB and Cyber Crime Cell with an aim to create India the most safest place of internet in the World.
ReplyDeleteIf you are searching for an Ethical Hackers Academy then you should be join Cyber Crime Awareness Society. Cyber Crime Awareness Society is one of the Best Ceh Training In Jaipur. Cyber Crime Awareness Society is IT Consulting Company managed by Ethical Hackers & IT professionals, working with Police Agencies and Cyber Crime Cell of Government in India. It is also backed by a team of Experts working with RAW, CBI, ATS, IB and Cyber Crime Cell with an aim to create India the safest place of internet in the World.