Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CalculateGCD
- {
- // CONDITION:
- // Write a program that calculates the greatest common divisor (GCD) of given two integers a and b. Use the Euclidean algorithm (find it in Internet).
- static void Main()
- {
- int a = int.Parse(Console.ReadLine());
- int b = int.Parse(Console.ReadLine());
- int sum;
- if (a != 0 && b != 0)
- {
- if (a < b)
- {
- sum = b - a;
- a = a - sum - sum;
- if (a == 0)
- {
- Console.WriteLine(sum);
- }
- else
- {
- if ((b %= a) == 0)
- {
- Console.WriteLine(a);
- }
- else if ((a %= b) == 0)
- {
- Console.WriteLine(b);
- }
- }
- }
- else if (a > b)
- {
- sum = a - b;
- b = b - sum - sum;
- if (b == 0)
- {
- Console.WriteLine(sum);
- }
- else
- {
- if ((a %= b) == 0)
- {
- Console.WriteLine(b);
- }
- else if ((b %= a) == 0)
- {
- Console.WriteLine(a);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment