-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnum2word.h
91 lines (89 loc) · 2.42 KB
/
num2word.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<stdio.h>
#include<string.h>
char *numberWords(int n)
{
char *ones[] = {"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine"};
char *tenTOtwenty[] = {"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen"};
char *tens[] = {"ten",
"twenty",
"thirty",
"forty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninety"};
// char *newTemp;
char storeTheword[100];
if (n < 10)
{
return ones[n - 1];
}
else if (n > 10 && n < 20)
{
return tenTOtwenty[(n % 10) - 1];
}
else if (n % 10 == 0 && n < 100)
{
return tens[(n / 10) - 1];
}
else if (n % 10 != 0 && n < 100)
{
strcpy(storeTheword, numberWords(n - n % 10));
strcat(storeTheword, numberWords(n % 10));
char *newTemp = storeTheword;
return newTemp;
}
else if (n > 99 && n < 1000)
{
if (n % 100 == 0)
{
strcpy(storeTheword, numberWords(n / 100));
strcat(storeTheword, "hundred");
char *newTemp = storeTheword;
return newTemp;
}
else
{
strcpy(storeTheword, numberWords(n - n % 100));
strcat(storeTheword, "and");
strcat(storeTheword, numberWords(n % 100));
char *newTemp = storeTheword;
return newTemp;
}
}
else if (n > 999 && n < 1000000)
{
if (n % 1000 == 0)
{
strcpy(storeTheword, numberWords(n / 1000));
strcat(storeTheword, "thousand");
char *newTemp = storeTheword;
return newTemp;
}
else
{
strcpy(storeTheword, numberWords(n - n % 1000));
strcat(storeTheword, "and");
strcat(storeTheword, numberWords(n % 1000));
char *newTemp = storeTheword;
return newTemp;
}
}
}