Menu
Coddy logo textTech

Recap - Product Array

Part of the Fundamentals section of Coddy's C# journey — lesson 59 of 69.

challenge icon

Challenge

Easy
Write a method named `Prod` which gets an array of numbers as argument and returns the product of all the numbers in the list. Reminder, product is the multiplication of all the numbers, for `[1, 2, 3]`, return `6 = 1 * 2 * 3`.

Try it yourself

using System;

public class Program {
    public static int Prod(int[] arr) {
        // Write your code below
        
    }

    public static void Main(string[] args) {
        string text = Console.ReadLine();
        string[] stringArr = text.Split(',');
        int[] arr = new int[stringArr.Length];
        for (int i = 0; i < stringArr.Length; i++) {
            arr[i] = int.Parse(stringArr[i]);
        }
        
        int result = Prod(arr);
        Console.WriteLine("Product of array elements: " + result);
    }
}

All lessons in Fundamentals