Preview:
#include <iostream>
using namespace std;

int sumOfDigits = 0;

void SumOfDigits(int n){
  if(n%10 == 0){
    cout << sumOfDigits;
    return;
  }
   
  sumOfDigits += n%10;
  n /= 10;
  SumOfDigits(n);
}

int main() {
    int n;
    cin >> n;
    
    SumOfDigits(n);
    return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter