/home/toolbox/public_html/solutions/113/11332/c.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 /*
16 * Author: Isaac Traxler
17 * Date: 2015-03-11
18 * Purpose:
19 * Problem: 11332
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 #define BIG int
27 BIG num;
28
29 void init()
30 {
31 /* FUNCTION init */
32 } /* FUNCTION init */
33
34 void dump()
35 {
36 /* FUNCTION dump */
37 } /* FUNCTION dump */
38
39 int getInput()
40 {
41 /* FUNCTION getInput */
42 int dataReadFlag;
43
44 scanf(" %d ", &num);
45 dataReadFlag = (0 != num);
46 return (dataReadFlag);
47 } /* FUNCTION getInput */
48
49 BIG add(BIG num)
50 {
51 /* FUNCTION add */
52 BIG tot;
53 BIG tmp;
54
55 tot = 0;
56 tmp = num;
57 while (0 < tmp)
58 {
59 /* while */
60 tot = tot + (tmp % 10);
61 tmp = tmp / 10;
62 } /* while */
63 return tot;
64 } /* FUNCTION add */
65
66 void process()
67 {
68 /* FUNCTION process */
69 while (9 < num)
70 {
71 /* while */
72 num = add(num);
73 } /* while */
74 printf("%d\n", num);
75 } /* FUNCTION process */
76
77 int main()
78 {
79 /* main */
80 int moreToDo;
81
82 init();
83 moreToDo = getInput();
84 while (moreToDo)
85 {
86 /* while */
87 process();
88 moreToDo = getInput();
89 } /* while */
90
91 return EXIT_SUCCESS;
92 } /* main */
93