NA JUŻ!!
Proszę przeprowadzić przez schemat algorytmu obliczania NWD parę liczb do momentu, gdy a=b tak jak na lekcji.
a=282
b=78


Odpowiedź :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Test

{

   internal class Program

   {

       static int readInt(string komunikat, int min = int.MinValue, int max = int.MaxValue)

       {

           string str;

           int n;

           while (true)

           {

               Console.WriteLine(komunikat);

               str = Console.ReadLine();

               try

               {

                   n = int.Parse(str);

                   if ((n < min) || (n > max))

                   {

                       Console.WriteLine($" Wprowadzona liczba jest z poza dozwolonego  zakresu<{min},{max}>");

                   }

                   break;

               }

               catch (FormatException)

               {

                   Console.WriteLine("Niepoprawny format liczby! ");

               }

               catch (OverflowException)

               {

                   Console.WriteLine($"Wprowadzona liczba jest z poza dopusczalnego zakresu dla typu int: <{int.MinValue},{int.MaxValue}>");

               }

               catch (ArgumentNullException)

               {

                   Console.WriteLine("Wprowadzono pusty łańcuch! ");

               }

           }

           return n;

       }

       static int NWD(int a, int b)

       {

           while (b != 0)

           {

               int c = a % b;

               a = b;

               b = c;

           }

           return a;

       }

       static void Main(string[] args)

       {

           int a = readInt("Podaj liczbę a: ");

           int b = readInt("Podaj liczbę b: ");

           Console.WriteLine($"Największy Wspólny Dzielnik liczb {a}, {b} wynosi: " + Program.NWD(a, b));

           Console.ReadKey();

       }

   }

}

Zobacz obrazek Domino1591