The digital root, 



X


{\displaystyle X}

, of a number, 



n


{\displaystyle n}

, is calculated:

 find 



X


{\displaystyle X}

 as the sum of the digits of 



n


{\displaystyle n}


 find a new 



X


{\displaystyle X}

 by summing the digits of 



X


{\displaystyle X}

, repeating until 



X


{\displaystyle X}

 has only one digit.
The additive persistence is the number of summations required to obtain the single digit.

The task is to calculate the additive persistence and the digital root of a number, e.g.:





627615


{\displaystyle 627615}

 has additive persistence 



2


{\displaystyle 2}

 and digital root of 



9


{\displaystyle 9}

;




39390


{\displaystyle 39390}

 has additive persistence 



2


{\displaystyle 2}

 and digital root of 



6


{\displaystyle 6}

;




588225


{\displaystyle 588225}

 has additive persistence 



2


{\displaystyle 2}

 and digital root of 



3


{\displaystyle 3}

;




393900588225


{\displaystyle 393900588225}

 has additive persistence 



2


{\displaystyle 2}

 and digital root of 



9


{\displaystyle 9}

;
The digital root may be calculated in bases other than 10.



See

 Casting out nines for this wiki's use of this procedure.
 Digital root/Multiplicative digital root
 Sum digits of an integer
 Digital root sequence on OEIS
 Additive persistence sequence on OEIS
 Iterated digits squaring


       IDENTIFICATION DIVISION.
       PROGRAM-ID. DIGITAL-ROOT.
 
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 INPUT-NUMBER     PIC 9(16).
          03 INPUT-DIGITS     REDEFINES INPUT-NUMBER,
                              PIC 9 OCCURS 16 TIMES.
          03 DIGIT-SUM        PIC 999.
          03 DIGIT-NO         PIC 99.
          03 PERSISTENCE      PIC 9.
 
       01 OUTPUT-FORMAT.
          03 O-NUMBER         PIC Z(15)9.
          03 FILLER           PIC X(16) VALUE ': PERSISTENCE = '.
          03 O-PERSISTENCE    PIC Z9.
          03 FILLER           PIC X(9) VALUE ', ROOT = '.
          03 O-ROOT           PIC Z9.
 
       PROCEDURE DIVISION.
       BEGIN.
           MOVE 627615 TO INPUT-NUMBER, PERFORM FIND-DIGITAL-ROOT.
           MOVE 39390 TO INPUT-NUMBER, PERFORM FIND-DIGITAL-ROOT.
           MOVE 588225 TO INPUT-NUMBER, PERFORM FIND-DIGITAL-ROOT.
           MOVE 393900588225 TO INPUT-NUMBER, PERFORM FIND-DIGITAL-ROOT.
           STOP RUN.
 
       FIND-DIGITAL-ROOT.
           MOVE ZERO TO PERSISTENCE.
           MOVE INPUT-NUMBER TO O-NUMBER.
           PERFORM SUMMATION UNTIL INPUT-NUMBER IS LESS THAN 10.
           MOVE INPUT-NUMBER TO O-ROOT.
           MOVE PERSISTENCE TO O-PERSISTENCE.
           DISPLAY OUTPUT-FORMAT.
 
       SUMMATION.
           MOVE ZERO TO DIGIT-SUM.
           ADD 1 TO PERSISTENCE.
           PERFORM ADD-DIGIT VARYING DIGIT-NO FROM 1 BY 1
               UNTIL DIGIT-NO IS GREATER THAN 16.
           MOVE DIGIT-SUM TO INPUT-NUMBER.
 
       ADD-DIGIT.
           ADD INPUT-DIGITS(DIGIT-NO) TO DIGIT-SUM.