0% found this document useful (0 votes)
4 views2 pages

TRABAJOS

The document contains two C# programs: one for calculating the greatest common divisor (GCD) using Euclid's algorithm and another for solving the Tower of Hanoi problem. The GCD program prompts the user for two numbers and outputs their GCD, while the Tower of Hanoi program takes an integer input representing the number of disks and prints the steps to move them between pegs. Both programs utilize recursion to perform their respective calculations.

Uploaded by

Alí Barriga
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)
4 views2 pages

TRABAJOS

The document contains two C# programs: one for calculating the greatest common divisor (GCD) using Euclid's algorithm and another for solving the Tower of Hanoi problem. The GCD program prompts the user for two numbers and outputs their GCD, while the Tower of Hanoi program takes an integer input representing the number of disks and prints the steps to move them between pegs. Both programs utilize recursion to perform their respective calculations.

Uploaded by

Alí Barriga
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/ 2

EUCLIDES

class Program

static void Main(string[] args)

Console.WriteLine("Ingresa el primer número:");

int num1 = int.Parse(Console.ReadLine());

Console.WriteLine("Ingresa el segundo número:");

int num2 = int.Parse(Console.ReadLine());

int resultado = Euclides(num1, num2);

Console.WriteLine("El máximo común divisor es: " + resultado);

Console.ReadKey();

static int Euclides(int a, int b)

if (b == 0)

return a;

else

return Euclides(b, a % b);

}
HANOI

class Program

static void Main (string [] args)

int n;

n = Convert.ToInt32(Console.ReadLine());

Hanoi (n, 'A', 'C', 'B');

static void Hanoi(int n, char from, char to, char temp)

if (n == 1)

Console.WriteLine($"Mover disco 1 de {from} a {to}");

else

Hanoi(n - 1, from, temp, to);

Console.WriteLine($"Mover disco {n} de {from} a {to}");

Hanoi(n - 1, temp, to, from);

Console.ReadKey();

You might also like