Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System;
  2. class CalculateGCD
  3. {
  4.     static void Main()
  5.     {
  6.         int a, b;
  7.         Console.Write("Enter value of \"a\": ");
  8.         while (!int.TryParse(Console.ReadLine(), out a))
  9.         {
  10.             Console.WriteLine("Invalid input.Try again.");
  11.             Console.Write("Enter value of \"a\": ");
  12.         }
  13.         Console.Write("Enter value of \"b\": ");
  14.         while (!int.TryParse(Console.ReadLine(), out b))
  15.         {
  16.             Console.WriteLine("Invalid input.Try again.");
  17.             Console.Write("Enter value of \"b\": ");
  18.         }
  19.  
  20.         while (b!=0)
  21.         {
  22.             int temp = b;
  23.             b = a % b;
  24.             a = temp;
  25.         }
  26.         Console.WriteLine(a);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement