Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int a, a1, b, b1, r = 0;
  10.             do
  11.             {
  12.                 Console.Write("Въведете а:");
  13.                 a = int.Parse(Console.ReadLine());
  14.  
  15.                 Console.Write("Въведи b:");
  16.                 b = int.Parse(Console.ReadLine());
  17.  
  18.                 if (a <= 0 || b <= 0) Console.WriteLine("Числа не са естествени, въведете отново:");
  19.             } while (a <= 0 || b <= 0);
  20.             a1 = a;
  21.             b1 = b;
  22.  
  23.             if (a < b)
  24.             {
  25.                
  26.                 do
  27.                 {
  28.                     r = a % b;
  29.                     a = b;
  30.                     b = r;
  31.                    
  32.                 }while (a % b != 0) ;
  33.             }
  34.             else
  35.             {
  36.                
  37.                 do
  38.                 {
  39.                     r = a % b;
  40.                     a = b;
  41.                     b = r;
  42.                    
  43.                 }while (a % b != 0) ;
  44.             }
  45.  
  46.            
  47.             Console.WriteLine("НОД на {0} и {1} = {2}", a1, b1, r);
  48.  
  49.  
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement