1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <stdbool.h>
5 
6 /* C99 bools */
7 _Bool just_a_flag = false;
8 bool another_flag = true;
9 
convert(int thousands,int hundreds,int tens,int ones)10 void convert(int thousands, int hundreds, int tens, int ones)
11 {
12 char *num[] = {"", "One", "Two", "Three", "Four", "Five", "Six",
13 	       "Seven", "Eight", "Nine"};
14 
15 char *for_ten[] = {"", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty",
16 		   "Seventy", "Eighty", "Ninty"};
17 
18 char *af_ten[] = {"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
19 		  "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen"};
20 
21   printf("\nThe year in words is:\n");
22 
23   printf("%s thousand", num[thousands]);
24   if (hundreds != 0)
25     printf(" %s hundred", num[hundreds]);
26 
27   if (tens != 1)
28     printf(" %s %s", for_ten[tens], num[ones]);
29   else
30     printf(" %s", af_ten[ones]);
31 
32   va_list jajaja;
33 }
34 
35 
main()36 int main()
37 {
38 int year;
39 int n1000, n100, n10, n1;
40 
41   printf("\nEnter the year (4 digits): ");
42   scanf("%d", &year);
43 
44   if (year > 9999 || year < 1000)
45   {
46     printf("\nError !! The year must contain 4 digits.");
47     exit(EXIT_FAILURE);
48   }
49 
50   n1000 = year/1000;
51   n100 = ((year)%1000)/100;
52   n10 = (year%100)/10;
53   n1 = ((year%10)%10);
54 
55   convert(n1000, n100, n10, n1);
56 
57 return 0;
58 }
59 
60 
61