정수의 각 자릿수 값들을 더해줘서 반환하는 문제이다.
using namespace std; int solution(int n) { int answer = 0; while (n) { answer += n % 10; n /= 10; } return answer; }