Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Greatest Common Divisor of 2 or more numbers.
//Greatest Common Divisor of 2 or more numbers. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Net; using System.IO; using System.Numerics; namespace Rextester { public static class Program { static BigInteger GreatestCommonFactor(BigInteger a, BigInteger b) { while (b != 0) { BigInteger temp = b; b = a % b; a = temp; } return a; } static BigInteger[] ToBigInteger(string[] arr) { BigInteger[] result = new BigInteger[arr.Length]; for (int i = 0; i < arr.Length; i++) { result[i] = BigInteger.Parse(arr[i]); } return result; } public static void Main(string[] args) { BigInteger[] numbers = ToBigInteger(Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); if (numbers.Length > 0) { BigInteger result = numbers[0]; for (int i = 1; i < numbers.Length; i++) { result = GreatestCommonFactor(result, numbers[i]); } Console.WriteLine(result.ToString()); } else { Console.WriteLine("Error: no numbers entered"); } } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
actions and tasks
sss
help sending dataGrid Rows to Access Table.
where index
bc160401882
First Test With Coder - 3 digit number into digits
learning1
SquareMatrixPlusFieldMatrix
nthFromLastElement
BC150401319
stackse - search stackoverflow differently
Please log in to post a comment.