Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- // Write a program that calculates the greatest common divisor (GCD) of given two numbers. Use the Euclidean algorithm (find it in Internet).
- class GreatestDivisor
- {
- static void Main()
- {
- int firstNum = int.Parse(Console.ReadLine());
- int secNum = int.Parse(Console.ReadLine());
- int devider = 0;
- int remainder = 0;
- int saver = 0;//save secNum value
- while (true)
- {
- devider = firstNum / secNum;
- remainder = devider * secNum;
- saver = secNum;
- secNum = firstNum - remainder;
- firstNum = saver;
- if (secNum == 0)
- {
- Console.WriteLine(saver);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement