/home/toolbox/public_html/solutions/113/11332/b.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 MAX_SIZE 12
27 char line[MAX_SIZE];
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(" %s ", line);
45 dataReadFlag = (0 != strcmp("0", line));
46 return (dataReadFlag);
47 } /* FUNCTION getInput */
48
49 int addChar(char line[])
50 {
51 /* FUNCTION addChar */
52 int tot = 0;
53 int i;
54
55 for (i=0; i<strlen(line); i++)
56 {
57 /* for */
58 tot = tot + line[i] - '0';
59 } /* for */
60 return tot;
61 } /* FUNCTION addChar */
62
63 int add(int num)
64 {
65 /* FUNCTION add */
66 int tot;
67 int tmp;
68
69 tot = 0;
70 tmp = num;
71 while (0 < tmp)
72 {
73 /* while */
74 tot = tot + (tmp % 10);
75 tmp = tmp / 10;
76 } /* while */
77 return tot;
78 } /* FUNCTION add */
79
80 void process()
81 {
82 /* FUNCTION process */
83 int num;
84
85 num = addChar(line);
86 while (9 < num)
87 {
88 /* while */
89 num = add(num);
90 } /* while */
91 printf("%d\n", num);
92 } /* FUNCTION process */
93
94 int main()
95 {
96 /* main */
97 int moreToDo;
98
99 init();
100 moreToDo = getInput();
101 while (moreToDo)
102 {
103 /* while */
104 process();
105 moreToDo = getInput();
106 } /* while */
107
108 return EXIT_SUCCESS;
109 } /* main */
110