Posts [프로그래머스] 약수의 합 / C++
Post
Cancel

[프로그래머스] 약수의 합 / C++


Contents



문제


문제를 보시려면 링크를 클릭해주세요.


풀이


1~n까지 돌며 나누어 떨어지는 수들을 answer에 더해줍니다.


소스 코드


1
2
3
4
5
6
7
8
9
10
11
12
#include <string>

using namespace std;

int solution(int n) {
    int answer = 0;
    for(int i=1; i<=n; i++){
        if(n%i==0)
            answer+=i;
    }
    return answer;
}



This post is licensed under CC BY 4.0 by the author.

[프로그래머스] 이상한 문자 만들기 / C++

[프로그래머스] 자릿수 더하기 / C++

Comments powered by Disqus.