Mohan S

Mohan S

  • NA
  • 34
  • 38.9k

Code - Finding GCD of array

Nov 6 2015 4:54 AM
Hi Guys, 
 
I get error with int[] conversion in the below code, please assist.
 
namespace GCD
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter the number");
int[] input = Convert.ToInt32(Console.ReadLine());
int output = UserProgramCode.GCD(input);
}
class UserProgramCode
{
public static int GCD(int[] array)
{
int a = 0, b = 0, gcd=0, t;
for (int i = 0; i < array.Length - 1; i++)
{
a = array[i];
b = array[i + 1];
while (b != 0)
{
t = b;
b = a % b;
a = t;
}
gcd = a;
}
return gcd;
}
 

Answers (6)