Advertisement
PlamenYovchev

Loops - Task 8

Dec 1st, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. using System;
  2.  
  3. class GCDEuclidius
  4. {
  5.     static void Main()
  6.     {
  7.         int firstN = int.Parse(Console.ReadLine());
  8.         int secondN = int.Parse(Console.ReadLine());
  9.         int greatestCD = 0;
  10.         for (int i = 1; i <= Int16.MaxValue; i++)
  11.         {
  12.             if (firstN % i == 0 && secondN % i == 0)
  13.             {
  14.                 greatestCD = i;
  15.             }
  16.             if ((i > firstN && firstN > secondN) || (i>secondN && secondN>firstN))
  17.             {
  18.                 break;
  19.             }
  20.         }
  21.         Console.WriteLine(greatestCD);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement