웅재의 코딩세상
[프로그래머스] 하샤드 수 본문
- 풀이
#include <string>
#include <vector>
using namespace std;
bool solution(int x) {
bool answer = true;
int sum=0;
int num = x;
while(num>0){
sum = sum + num%10;
num = num/10;
}
if(x % sum != 0) {
answer = false;
}
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 1' 카테고리의 다른 글
[프로그래머스] 콜라츠 추측 (0) | 2024.02.09 |
---|---|
[프로그래머스] 평균 구하기 (0) | 2024.02.09 |
[프로그래머스] 핸드폰 번호 가리기 (0) | 2024.02.09 |
[프로그래머스] 행렬의 덧셈 (0) | 2024.02.09 |
[프로그래머스] x만큼 간격이 있는 n개의 숫자 (0) | 2024.02.09 |