반응형
SMALL
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
bool solution(int x) {
bool answer = true;
int x2 = x;
int s = 0;
while (x) {
s += x % 10;
x /= 10;
}
if (x2 % s != 0) answer = false;
return answer;
}
#include <iostream>
using namespace std;
bool solution(int x) {
bool answer = true;
int s = 0;
int temp;
temp = x;
while (temp) {
s+= temp % 10;
temp /= 10;
}
if (x%s ==0) answer = true;
else answer = false;
return answer;
}
반응형
LIST
'알고리즘 문제 풀이 > Programmers' 카테고리의 다른 글
행렬의 덧셈 - 1단계 (C++) (0) | 2019.06.26 |
---|---|
피보나치 수 - 2단계 (C, C++) (0) | 2019.06.26 |
콜라츠 추측 - 1단계 (C, C++) (0) | 2019.06.26 |
정수 제곱근 판별 - 1단계 (C, C++) (0) | 2019.06.26 |
자연수 뒤집어 배열로 만들기 - 1단계 (C, C++) (0) | 2019.06.26 |