Menu
Coddy logo textTech

요약 - Product Array

Coddy C# 여정의 기초 섹션에 포함된 레슨 — 69개 중 59번째.

challenge icon

챌린지

쉬움
숫자 배열을 인자로 받아 리스트에 있는 모든 숫자의 곱을 반환하는 `Prod`라는 이름의 메서드를 작성하세요. 참고로, 곱은 모든 숫자를 곱한 결과입니다. 예를 들어 `[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);
    }
}

기초의 모든 레슨