Skip to content

Instantly share code, notes, and snippets.

@IvanNikolov
Created October 23, 2014 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IvanNikolov/a2896c77f1dc5787679b to your computer and use it in GitHub Desktop.
Save IvanNikolov/a2896c77f1dc5787679b to your computer and use it in GitHub Desktop.
using System;
class CalculateGCD
{
static void Main(string[] args)
{
// function gcd(a, b)
// while b ≠ 0
// t := b
// b := a mod b
// a := t
// return a
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
int gcd = a%b;
while (b !=0)
{
b = gcd;
a = b;
break;
} Console.WriteLine(a);
//OPTION 2
//int a = int.Parse(Console.ReadLine());
//int b = int.Parse(Console.ReadLine());
//int gcd = 0;
//while (a > b || b > a)
//{
// if (a > b && a > 0 && b > 0)
// {
// gcd = Math.Abs(a - b);
// //Console.WriteLine(gcd);
// }
// else if (a <= 0)
// {
// gcd = b;
// }
// else if (b <= 0)
// {
// gcd = a;
// }
// else
// {
// gcd = Math.Abs(b - a);
// //Console.WriteLine(gcd);
// } break;
//} Console.WriteLine(gcd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment