/home/toolbox/public_html/solutions/4/443/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 #define MAX_LINE 257
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2016-04-19
20 * Purpose: fun
21 * Problem: 443 - humber numbers
22 */
23
24 /*
25 * This template reads lines of data at a time until end of file.
26 */
27
28 #define MAX_NUMBERS 6000
29 #define UPPER_LIMIT 2000000001
30
31 int num;
32 long int h[MAX_NUMBERS];
33 int cnt;
34
35 int compare(const void *a, const void *b)
36 {
37 /* FUNCTION compare */
38 return ( *(int*)a - *(int*)b );
39 } /* FUNCTION compare */
40
41 void init()
42 {
43 /* FUNCTION init */
44 long int i2;
45 long int i3;
46 long int i5;
47 long int i7;
48 long int t2;
49 long int t23;
50 long int t235;
51 long int t2357;
52
53 cnt = 1;
54 h[0] = 1;
55
56 for (i2=1; UPPER_LIMIT>i2; i2=i2*2)
57 {
58 /* for each multiple of 2 */
59 t2 = i2;
60 for (i3=1; UPPER_LIMIT>(i2*i3); i3=i3*3)
61 {
62 /* for each multiple of 3 */
63 t23 = i3 * t2;
64 for (i5=1; UPPER_LIMIT>(i2*i3*i5); i5=i5*5)
65 {
66 /* for each multiple of 5 */
67 t235 = t23 * i5;
68 for (i7=1; UPPER_LIMIT>(i2*i3*i5*i7); i7=i7*7)
69 {
70 /* for each multiple of 7 */
71 t2357 = t235 * i7;
72 h[cnt] = t2357;
73 cnt++;
74 } /* for each multiple of 7 */
75 } /* for each multiple of 5 */
76 } /* for each multiple of 3 */
77 } /* for each multiple of 2 */
78 qsort(h, cnt, sizeof(long int), compare);
79 } /* FUNCTION init */
80
81 void dump()
82 {
83 /* FUNCTION dump */
84 } /* FUNCTION dump */
85
86 int getInput()
87 {
88 /* FUNCTION getInput */
89 int dataReadFlag;
90 scanf(" %d ", &num);
91 dataReadFlag = (0 != num);
92 return (dataReadFlag);
93 } /* FUNCTION getInput */
94
95 void process()
96 {
97 /* FUNCTION process */
98
99 printf("The %d", num);
100 if ((1 == (num % 10)) && (11 != (num % 100)))
101 {
102 printf("st");
103 }
104 else
105 {
106 /* not a first */
107 if ((2 == (num % 10)) && (12 != (num % 100)))
108 {
109 printf("nd");
110 }
111 else
112 {
113 /* not a second */
114 if ((3 == (num % 10)) && (13 != (num % 100)))
115 {
116 printf("rd");
117 }
118 else
119 {
120 /* not a third */
121 printf("th");
122 } /* not a third */
123 } /* not a second */
124 } /* not a first */
125 printf(" humble number is %ld.\n", h[num]);
126 } /* FUNCTION process */
127
128 int main()
129 {
130 /* main */
131 int moreToDo;
132
133 init();
134 moreToDo = getInput();
135 while (moreToDo)
136 {
137 /* while */
138 process();
139 moreToDo = getInput();
140 } /* while */
141
142 return EXIT_SUCCESS;
143 } /* main */
144