// calcula cantidad total de letras de los nombres (en inglés) // de los numeros enteros positivos desde a hasta b void nomNum(char n[], int x) { /* nombre de numero, en ingles asume ‘string.h’ */ char u[][10] = {"","one","two","three","four","five","six","seven","eight", "nine","ten","eleven","twelve","thirteen","fourteen","fifteen", "sixteen","seventeen","eighteen","nineteen"}; char d[][9] = {"","","twenty","thirty","forty","fifty","sixty","seventy", "eighty","ninety"}; char c[] = "hundred"; char m[] = "onethousand"; char y[] = "and"; int dg[4]; /* digitos aislados, posicion digito */ int cx = x, nd = 0; /* copia de x, numero de digitos */ int du; /* unidades (menos de 20) */ for ( ; nd < 4; nd++) { dg[nd] = x%10; x /= 10; } if (cx < 20) strcpy(n,u[cx]); else if (cx < 100) { strcpy(n,d[dg[1]]); if (dg[0] > 0) strcat(n,u[dg[0]]); } else if (cx < 1000) { strcpy(n,u[dg[2]]); strcat(n,c); if (dg[1] || dg[0]) { strcat(n,y); du = 10*dg[1]+dg[0]; if (du < 20) strcat(n,u[du]); else { strcat(n,d[dg[1]]); strcat(n,u[dg[0]]); } } } else if (cx < 1001) strcpy(n,m); } long lonNomNum(int i, int d) { /* total de letras de nombres de numeros de i d (en ingles) asume ‘string.h’ */ long lt = 0; /* longitud todos los nombres */ char nom[50]; /* nombre de un numero */ for ( ; i <= d; i++) { nomNum(nom, i); lt += strlen(nom); } return lt; } ecabrera, intec, diciembre 2007.