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