Recap - Product Array
Part of the Fundamentals section of Coddy's C# journey — lesson 59 of 69.
Challenge
EasyWrite 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
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic Shortcuts5Operators Part 2
Comparison OperatorsLogical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 311Arrays Basics
Declaring ArraysAccessing ElementsModifying ArraysArray MethodsRecap - Product ArrayEdit Recap - Reversed Array