Răspuns:
#include<iostream>
using namespace std;
int main()
{
int n;
cin >>n;
if(n >= 10 && n < 100)
cout << n%10 + n/10;
if(n>=100 && n<1000)
cout << n%10 + n/10%10 + n/100;
if(n>=1000 && n< 10000)
cout << n%10 + n/10%10 + n/100%10 + n/1000;
return 0;
}
Explicație: