Menu
Coddy logo textTech
flag Ar iconالعربيةdown icon

مراجعة - مصفوفة المنتجات

جزء من قسم Fundamentals في رحلة C# على Coddy — الدرس 59 من 69.

challenge icon

التحدي

سهل
اكتب دالة برمجية (method) تسمى `Prod` تستقبل مصفوفة من الأرقام كمعامل (argument) وتعيد حاصل ضرب جميع الأرقام في القائمة. تذكير، حاصل الضرب هو ناتج ضرب جميع الأرقام، بالنسبة لـ `[1, 2, 3]`، تعيد `6 = 1 * 2 * 3`.

جرّب بنفسك

using System;

public class Program {
    public static int Prod(int[] arr) {
        // اكتب الكود الخاص بك أدناه
        
    }

    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);
    }
}

جميع دروس Fundamentals