我有一个任务,我需要找到数组中的所有数字的乘积,我不知道如何做到这一点。如何乘数组中的所有值?
int[] numbers = new int[SIZE];
Console.WriteLine("Type in 10 numbers");
Console.WriteLine("To stop, type in 0");
for (int input = 0; input < SIZE; input++)
{
userInput = Console.ReadLine();
numberInputed = int.Parse(userInput);
if (numberInputed == ZERO)
{
numberInputed = ONE;
break;
}
else
{
numbers[input] = numberInputed;
}
}
这就是我试图找到数组中所有数字的乘积的地方。
foreach (int value in numbers)
{
prod *= value;
}
Console.WriteLine("The product of the values you entered is {0}", prod);
我在foreach语句中做了什么错误?在此先感谢
编辑,离开了我的声明价值
const int SIZE = 10;
const int ZERO = 0;
string userInput;
int numberInputed;
int prod = 1;
现在,当我在所有十个值类型的作品,但如果我为了打破循环放了0,那么一切都等于0怎么办我阻止0进入数组?
什么是与去错你的代码? –