웅재의 코딩세상

[프로그래머스] 약수의 합 본문

코딩테스트/프로그래머스 - LV 1

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

웅드 2024. 2. 9. 17:20

 

  • 풀이
#include <string>
#include <vector>

using namespace std;

int solution(int n) {
    int answer = 0;
    for(int i=1; i<n+1; i++){
        if(n % i ==0){
            answer += i;
        }
        else
            continue;
    }
    return answer;
}
반응형