Problem Description the digital root of a positive integer is found by
Summing the digits of the integer. If The resulting value is a single
Digit then, digit is the digital root. If the resulting value
Contains or more digits, those digits is summed and the process
is repeated. This is continued as long as necessary to obtain a single
Digit.
For example, consider the positive integer 24. Adding the 2 and the 4
Yields a value of 6. Since 6 is a single digit, 6 is the digital root
of 24. Now consider the positive integer 39. Adding the 3 and the 9
Yields 12. Since Digit, the process must be
Repeated. Adding the 1 and the 2 Yeilds 3, a single digit and also the
Digital root of 39.
Input the input file would contain a list of positive integers, one per
Line. The end of the input would be indicated by an integer value of
Zero.
Output for each integer in the input, output it digital root on a
Separate line of the output.
Sample Input
24 39 0
Sample Output
6 3
The topic examines the nine-odd theorem.
#include <stdio.h>#include <string.h>Charn[10001];intAdd_digital (Const Char* Str) {intresult =0;Char* pointer = (Char*) str; while(*pointer) {result + = *pointer- -; pointer++; }returnResult;}intMain () { while(scanf('%s ', N)) {if(!strcmp(N,"0")) Break;intsum = Add_digital (n);printf("%d\n", (Sum-1)%9+1); }return 0;}
"Solving"-avionics OJ1013 Digital Roots