Advertisement
Martichka

Loops/Task 8 - GCD Second Version

Dec 10th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using System;
  2. class GreatestCommonDivisorSecondVersion
  3. {
  4.     static void Main()
  5.     {
  6.         Console.WriteLine("enter two numbers:");
  7.         int firstValue = int.Parse(Console.ReadLine());
  8.         int secondValue = int.Parse(Console.ReadLine());
  9.         bool check = secondValue % firstValue != 0;
  10.         bool checkTwo = firstValue % secondValue != 0;
  11.         if ((secondValue < firstValue) && (firstValue != 0) && (secondValue != 0))
  12.         {
  13.             while ((firstValue != 0) && (secondValue != 0))
  14.             {
  15.                 firstValue %= secondValue;
  16.                 if ((firstValue == 0) || (secondValue == 0))
  17.                 {
  18.                     break;
  19.                 }
  20.                 secondValue %= firstValue;
  21.             }
  22.             if (firstValue == 0)
  23.             {
  24.                 Console.WriteLine("The Greatest Common Divisor of yout numbers is: " + secondValue);
  25.             }
  26.             else if (secondValue == 0)
  27.             {
  28.                 Console.WriteLine("The Greatest Common Divisor of yout numbers is: " + firstValue);
  29.             }
  30.         }
  31.         else if ((firstValue < secondValue) && (firstValue != 0) && (secondValue != 0))
  32.         {
  33.             while ((firstValue != 0) && (secondValue != 0))
  34.             {
  35.                 secondValue %= firstValue;
  36.                 if ((firstValue == 0) || (secondValue == 0))
  37.                 {
  38.                     break;
  39.                 }
  40.                 firstValue %= secondValue;
  41.             }
  42.  
  43.             if (firstValue == 0)
  44.             {
  45.                 Console.WriteLine("The Greatest Common Divisor of yout numbers is: " + secondValue);
  46.             }
  47.             else if (secondValue == 0)
  48.             {
  49.                 Console.WriteLine("The Greatest Common Divisor of yout numbers is: " + firstValue);
  50.             }
  51.         }
  52.         else
  53.         {
  54.             Console.WriteLine("Wrong Input!");
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement