1: 2: static char sccsid[] = " number.c 4.1 82/10/24 "; 3: 4: #include <stdio.h> 5: 6: int flag; 7: int max = 21; 8: char *card[] = 9: { 10: "hundred", 11: "thousand", 12: "million", 13: "billion", 14: "trillion", 15: "quadrillion", 16: "quintillion", 17: "sextillion", 18: "septillion", 19: "octillion", 20: "nonillion", 21: "decillion", 22: "undecillion", 23: "duodecillion", 24: "tredecillion", 25: "quattuordecillion", 26: "quindecillion", 27: "sexdecillion", 28: "septendecillion", 29: "octodecillion", 30: "novemdecillion", 31: "vigintillion" 32: }; 33: char *unit[] = { 34: "zero", 35: "one", 36: "two", 37: "three", 38: "four", 39: "five", 40: "six", 41: "seven", 42: "eight", 43: "nine" 44: }; 45: char *teen[] = { 46: "ten", 47: "eleven", 48: "twelve", 49: "thirteen", 50: "fourteen", 51: "fifteen", 52: "sixteen", 53: "seventeen", 54: "eighteen", 55: "nineteen" 56: }; 57: char *decade[] = { 58: "zero", 59: "ten", 60: "twenty", 61: "thirty", 62: "forty", 63: "fifty", 64: "sixty", 65: "seventy", 66: "eighty", 67: "ninety" 68: }; 69: char line[100]; 70: main() 71: { 72: register c, i, fraction; 73: int r; 74: 75: 76: fraction = 0; 77: while((c = getchar()) != EOF) { 78: if(!digit(c)) { 79: fraction = (c == '.'); 80: putchar(c); 81: continue; 82: } 83: if(fraction) { 84: while(digit(c)) { 85: putchar(' '); 86: putchar(c); 87: if((c=getchar()) == EOF) 88: exit(1); 89: } 90: putchar(' '); 91: goto out; 92: } 93: 94: putchar(' '); 95: i = 0; 96: line[i++] = '0'; 97: line[i++] = '0'; 98: while(c == '0') 99: if((c=getchar()) == EOF) 100: exit(1); 101: while(digit(c)) { 102: if(i < 98) 103: line[i++] = c; 104: if((c=getchar()) == EOF) 105: exit(1); 106: } 107: line[i] = 0; 108: r = i/3; 109: if(r == 0) { 110: print("zero"); 111: goto out; 112: } 113: conv(line+i-3*r, r); 114: 115: out: 116: fraction = (c == '.'); 117: nline(); 118: printf("...\n"); 119: if(c != '\n') 120: putchar(c); 121: } 122: } 123: 124: conv(p, c) 125: char *p; 126: { 127: 128: if(c > max) { 129: conv(p, c-max); 130: print(card[max]); 131: nline(); 132: p += (c-max)*3; 133: c = max; 134: } 135: while(c > 1) { 136: c--; 137: conv(p, 1); 138: cprint(card[c]); 139: nline(); 140: p += 3; 141: } 142: ones(p[0]); 143: cprint(card[0]); 144: tens(p); 145: ones(p[2]); 146: } 147: 148: ones(d) 149: { 150: if(d=='0') 151: return; 152: print(unit[d-'0']); 153: } 154: 155: tens(p) 156: char *p; 157: { 158: 159: switch(p[1]) { 160: 161: case '0': 162: return; 163: 164: case '1': 165: print(teen[p[2]-'0']); 166: p[2] = '0'; 167: return; 168: } 169: 170: print(decade[p[1]-'0']); 171: } 172: 173: 174: digit(c) 175: { 176: 177: if(c < '0' || c > '9') 178: return(0); 179: return(1); 180: } 181: 182: nline() 183: { 184: 185: if(flag) 186: printf(".\n"); 187: flag = 0; 188: } 189: 190: cprint(s) 191: { 192: 193: if(flag) 194: print(s); 195: } 196: 197: print(s) 198: { 199: 200: if(flag) 201: printf(" "); 202: printf(s); 203: flag = 1; 204: }