SoFunction
Updated on 2025-04-13

The JavaScript string is split into a single character and sums up to no more than 10 to find the final value


@echo off
color 0A
echo Please enter the number:
set /p age=
echo ---------------
title %age%
set sum=0
set get=0
set call_num=0
:: Calculate string length
:begin
set /a call_num+=1
echo %call_num% cycle
set str=%age%
set num=0
:next1
if not "%str%"=="" (
set /a num+=1
set "str=%str:~1%"
goto next1
)
echo Current number %age%
@echo.
set i=%num%
:loop
set /a i-=1
set "get=%age:~-1%"
set "age=%age:~0,-1%"
set /a sum+=get
if not "%age%"=="" (
goto loop
)
if %sum% gtr 10 (
set age=%sum%
set sum=0
goto begin
)
echo final result: %sum%
pause