/home/toolbox/public_html/solutions/109/10931/a.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: 2016-03-29
18 * Purpose: fun
19 * Problem: 10931 - Parity
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 #define NUM long int
27 NUM 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(" %ld ", &num);
45 dataReadFlag = (0 != num);
46 return (dataReadFlag);
47 } /* FUNCTION getInput */
48
49 void process()
50 {
51 /* FUNCTION process */
52 int i;
53 int cnt = 0;
54 char line[100];
55 int lcnt = 0;
56
57 while (0 < num)
58 {
59 /* while */
60 if (1 == (num % 2))
61 {
62 /* 1 */
63 cnt++;
64 line[lcnt] = '1';
65 } /* 1 */
66 else
67 {
68 /* 0 */
69 line[lcnt] = '0';
70 } /* 0 */
71 num = num / 2;
72 lcnt++;
73 } /* while */
74 printf("The parity of ");
75 for (i=lcnt-1; 0<=i; i--)
76 {
77 /* for each digit */
78 printf("%c", line[i]);
79 } /* for each digit */
80 printf(" is %d (mod 2).\n", cnt);
81 } /* FUNCTION process */
82
83 int main()
84 {
85 /* main */
86 int moreToDo;
87
88 init();
89 moreToDo = getInput();
90 while (moreToDo)
91 {
92 /* while */
93 process();
94 moreToDo = getInput();
95 } /* while */
96
97 return EXIT_SUCCESS;
98 } /* main */
99