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;
}
Ravi PatelPosted Nov 6, 2015, 6:24 AM
{
static void Main(string[] args)
{
Console.WriteLine("Please Enter the size of array");
int n =Convert.ToInt32( Console.ReadLine());
int[] input = new int[n];
Console.WriteLine("Please enter the number");
for (int i = 0; i
string line = Console.ReadLine();
int value;
if (int.TryParse(line, out value))
{
input[i] = value;
}
else
{
Console.WriteLine("Not an integer!");
}
}
//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;
}
}
}
Ravi PatelPosted Nov 6, 2015, 6:33 AM
Mohan SPosted Nov 6, 2015, 6:30 AM
Ravi PatelPosted Nov 6, 2015, 6:17 AM
{
static void Main(string[] args)
{
int[] input = new int[5];
Console.WriteLine("Please enter the number");
for (int i = 0; i
string line = Console.ReadLine();
int value;
if (int.TryParse(line, out value))
{
input[i] = value;
}
else
{
Console.WriteLine("Not an integer!");
}
}
//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;
}
}
}
Mohan SPosted Nov 6, 2015, 5:49 AM
Ravi PatelPosted Nov 6, 2015, 5:20 AM
{
static void Main(string[] args)
{
Console.WriteLine("Please enter the number");
int[] input = new int[5];
for (int i = 0; i < input.Length; i++)
{
input[i] = Convert.ToInt32(Console.ReadLine());
}
//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;
}
}
}