Facebook
From Kuc, 6 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 242
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication29
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int a, b;
  14.             int i = 0;
  15.  
  16.             Console.WriteLine("Podaj liczbę: ");
  17.             while (!int.TryParse(Console.ReadLine(), out a)&& a<=0)
  18.                 Console.WriteLine("Błędna wartość, podaj jeszcze raz...");
  19.  
  20.  
  21.             Console.WriteLine("Podaj drugą liczbę: ");
  22.             while (!int.TryParse(Console.ReadLine(), out b)&& b <=0)
  23.                 Console.WriteLine("Błędna wartość, podaj jeszcze raz...");
  24.  
  25.        
  26.                 while(a!=b)
  27.                 {
  28.                 if (a > b)
  29.                 {
  30.                     a = a - b;
  31.                     i++;
  32.                     Console.WriteLine("{2}. A= {0} B= {1}", a, b, i);
  33.                     Console.WriteLine(" ");
  34.                 }
  35.                 else
  36.                 {
  37.                     b = b - a;
  38.                     i++;
  39.                     Console.WriteLine("{2}. A= {0} B= {1}", a, b, i);
  40.                     Console.WriteLine(" ");
  41.  
  42.                 }
  43.             }
  44.            
  45.  
  46.             Console.WriteLine("NWD = {0}",a);
  47.             Console.ReadKey();
  48.  
  49.  
  50.  
  51.  
  52.         }
  53.     }
  54. }
  55.