Created
October 23, 2014 13:25
-
-
Save IvanNikolov/a2896c77f1dc5787679b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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