blob: 12c4a33d9ec56dfcf07c812d097854653b299b68 [file] [log] [blame]
Eli Benderskya2915862012-06-23 06:25:53 +03001#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4
5void convert(int thousands, int hundreds, int tens, int ones)
6{
7char *num[] = {"", "One", "Two", "Three", "Four", "Five", "Six",
8 "Seven", "Eight", "Nine"};
9
10char *for_ten[] = {"", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty",
11 "Seventy", "Eighty", "Ninty"};
12
13char *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
29int main()
30{
31int year;
32int 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
50return 0;
51}
52
53