Advertisement
BojidarDosev

zadacha v chas Hanoi

Sep 30th, 2021
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp23
  8. {
  9.     class Program
  10.     {
  11.         static void Hanoi (string a, string b, string c, int n)
  12.         {
  13.             if (n == 1) Console.WriteLine("premesti disk ot " + a + " na " + c);
  14.             else
  15.             {
  16.                 Hanoi(a, c, b, n - 1);
  17.                 Console.WriteLine("premesti disk ot " + a + " na " + c);
  18.                 Hanoi(b, a, c, n - 1);
  19.             }
  20.  
  21.         }
  22.  
  23.         static void Main(string[] args)
  24.         {
  25.             string a = "A";
  26.             string b = "B";
  27.             string c = "C";
  28.             Hanoi(a, b, c, 4);
  29.         }
  30.     }
  31. }
  32. using System;
  33. using System.Collections.Generic;
  34. using System.Linq;
  35. using System.Text;
  36. using System.Threading.Tasks;
  37.  
  38. namespace ConsoleApp23
  39. {
  40.     class Program
  41.     {
  42.         static void Hanoi (string a, string b, string c, int n)
  43.         {
  44.             if (n == 1) Console.WriteLine("premesti disk ot " + a + " na " + c);
  45.             else
  46.             {
  47.                 Hanoi(a, c, b, n - 1);
  48.                 Console.WriteLine("premesti disk ot " + a + " na " + c);
  49.                 Hanoi(b, a, c, n - 1);
  50.             }
  51.  
  52.         }
  53.  
  54.         static void Main(string[] args)
  55.         {
  56.             string a = "A";
  57.             string b = "B";
  58.             string c = "C";
  59.             Hanoi(a, b, c, 4);
  60.         }
  61.     }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement