728x90
https://school.programmers.co.kr/learn/courses/30/lessons/181935
📝 나의 풀이
using System;
public class Solution {
public int solution(int n) {
int answer = 0;
if(n%2!=0){
for(int i=1; i<=n; ){
answer += i;
i = i+2;
}
} else {
for(int i=2; i<=n; ){
answer = answer+ (i*i);
i = i+2;
}
}
return answer;
}
}
728x90
'코딩테스트 > [C#] 프로그래머스' 카테고리의 다른 글
[프로그래머스 | C# | Lv.0] 더 크게 합치기 (0) | 2023.09.04 |
---|---|
[프로그래머스 | C# | Lv.0] 홀짝 구분하기 (0) | 2023.09.04 |
[프로그래머스 | C# | Lv.0] 배열의 길이에 따라 다른 연산하기 (0) | 2023.09.04 |
[프로그래머스 | C# | Lv.0] 홀수 vs 짝수 (0) | 2023.09.04 |
[프로그래머스 | C# | Lv.0] 문자열 붙여서 출력하기 (0) | 2023.09.04 |