let rec sum x = if x = 0 then 0 else x mod 10 + sum (x / 10)

let () =
  let rec loop () =
    let x = Scanf.scanf "%d\n" (fun x -> x) in
    if x = 0 then ()
    else (Printf.printf "%d\n" (sum x); loop ()) in
  loop ()