且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将数组中的所有元素相乘?

更新时间:2023-02-10 15:39:09

这可能会更好一些,尽管还有很多工作要做!

This might be a LITTLE better, although there is still quite a bit of tidying up to do!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Program
{
class Third
{

    public static void Main()
    {

        Console.WriteLine("Enter how many numbers");

        int howMuch = int.Parse(Console.ReadLine());

        int[] num = new int[howMuch];

        int sum = 1;
        for(int i=0;i<num.Length;i++) //allows you to fill the array
        {
           Console.WriteLine("Please enter an integer");
            sum *= int.Parse(Console.ReadLine()); // this will now multiply the value to sum, as your comment suggests
        }

        Console.WriteLine(sum);

        Console.ReadLine();

    }

}
}

编辑

sum *= num[i];

应该做你想做的事!