Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace fuggvenyek
- {
- class Program
- {
- static int count;
- static void hanoi(int n, char a, char b, char c)
- {
- if (n == 1)
- {
- count++;
- Console.WriteLine("{0} -> {1}", a, c);
- }
- else
- {
- hanoi(n - 1, a, c, b);
- count++;
- Console.WriteLine("{0} -> {1}", a, c);
- hanoi(n - 1, b, a, c);
- }
- }
- static void Main(string[] args)
- {
- Console.Write("Kérem a korongok számát: ");
- int n = Convert.ToInt32(Console.ReadLine());
- if (n > 0)
- {
- hanoi(n, 'A', 'B', 'C');
- }
- Console.WriteLine("Lépések száma: {0}", count);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement