Advertisement
EndymionSpr

NWD3

Oct 18th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 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 ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             /* int a, b;
  14.              A:
  15.              Console.WriteLine("Podaj a.");
  16.              a = int.Parse(Console.ReadLine());
  17.              Console.WriteLine("Podaj b.");
  18.              b = int.Parse(Console.ReadLine());
  19.              if (a == 0 || b == 0) { Console.WriteLine("Błędna liczba! "); goto A; }
  20.              while (a != b)
  21.              {
  22.                  if (a > b)
  23.                      a -= b;
  24.                  else
  25.                      b -= a;
  26.              }
  27.  
  28.              Console.WriteLine("Największy wspólny dzielnik (NWD) to: " + a);
  29.              Console.ReadKey(); */
  30.             int a, b;
  31.             while (true)
  32.             {
  33.                 Console.WriteLine("Podaj a.");
  34.                 a = int.Parse(Console.ReadLine());
  35.                 Console.WriteLine("Podaj b.");
  36.                 b = int.Parse(Console.ReadLine());
  37.                 if (a == 0 || b == 0) Console.WriteLine("Błędna liczba! ");
  38.                 else break;
  39.             }
  40.             while (a != b)
  41.             {
  42.                 if (a > b)
  43.                     a -= b;
  44.                 else
  45.                     b -= a;
  46.             }
  47.  
  48.             Console.WriteLine("Największy wspólny dzielnik (NWD) to: " + a);
  49.             Console.ReadKey();
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement