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

[프로그래머스] 자릿수 더하기

웅드 2024. 2. 9. 17:18

 

  • 풀이
#include <iostream>

using namespace std;
int solution(int n)
{
    int answer = 0;
    while(n>0){
        answer += n%10;
        n = n / 10;
    }
    return answer;
}
반응형