Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: pupu

Problemset: ผลรวมของเลขหลัก

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-06 11:45:10

#include <iostream>
#include <vector>
using namespace std;
int main(){ios::sync_with_stdio(0);cin.tie(0);
    long long int n,sum=0,ten=1,x;
    cin>>n;
    std::string lung = std::to_string(n);
    int how = lung.length();
        for (int i=0;i<how-1;i++){
            ten = ten *10;
        }
        for(int i=0;i<how;i++){
            x = n/ten;
            n = n - (x*ten);
            sum = sum+x;
            ten = ten/10;
        }
    cout<<sum;
}