본문 바로가기

알고리즘 문제 풀이/Programmers

약수의 합 - 1단계 (C, C++)

반응형
SMALL
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

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

#include <vector>
#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;
}
반응형
LIST