using System;
public class Solution {
public int solution(int[] num_list) {
int answer = 0;
int mul = 1;
for(int i = 0; i < num_list.Length; i++)
{
if(num_list.Length >= 11)
{
answer += num_list[i];
}
else if(num_list.Length <= 10)
{
mul *= num_list[i];
answer = mul;
}
}
return answer;
}
}
✍ 곱셈의 경우 초기값이 0이면 곱셈이 되지 않기 때문에 1로 초기화한 변수 mul을 선언하여 사용하였다.
'프로그래머스 > Lv.0' 카테고리의 다른 글
[프로그래머스 C#} 접두사인지 확인하기 (0) | 2023.08.06 |
---|---|
[프로그래머스 C#] 정수 부분 (0) | 2023.08.06 |
[프로그래머스 C#] 공배수 (0) | 2023.08.05 |
[프로그래머스 C#] 짝수는 싫어요 (0) | 2023.08.04 |
[프로그래머스 C#] 중앙값 구하기 (0) | 2023.08.04 |