Título: ayuda como puedo reducir esta codificacion Publicado por: daxelmejor en 17 Mayo 2010, 14:35 pm ector de 10 posiciones e ingresar x teclado ese vector y en otro vector hacer q se asignen el numero ingresado en letras es de 1 al 100
quiero reducirlo porqeu esta muy largo ojala me puedan ayudar int main() { const int d=10; const char x=20; char m1
int n; int m[d]; for (j=0;j<=9;j++) { cin>>n; m[j]=n; } for (j=0;j<=9;j++) { if (m[j]==1) { cout<< m[j] <<" " <<m1 <<endl; } if (m[j]==2) { cout<< m[j] <<" " <<m2 <<endl; } if (m[j]==3) { cout<< m[j] <<" " <<m3 <<endl; } if (m[j]==4) { cout<< m[j] <<" " <<m4 <<endl; } if (m[j]==5) { cout<< m[j] <<" " <<m5 <<endl; } if (m[j]==6) { cout<< m[j] <<" " <<m6 <<endl; } if (m[j]==7) { cout<< m[j] <<" " <<m7 <<endl; } if (m[j]==8) { cout<< m[j] <<" " <<m8 <<endl; } if (m[j]==9) { cout<< m[j] <<" " <<m9 <<endl; } if (m[j]==10) { cout<< m[j] <<" " <<m10 <<endl; } if (m[j]==11) { cout<< m[j] <<" " <<m11 <<endl; } if (m[j]==12) { cout<< m[j] <<" " <<m12 <<endl; } if (m[j]==13) { cout<< m[j] <<" " <<m13 <<endl; } if (m[j]==14) { cout<< m[j] <<" " <<m14 <<endl; } if (m[j]==15) { cout<< m[j] <<" " <<m15 <<endl; } if (m[j]==16) { cout<< m[j] <<" " <<m16 <<endl; } if (m[j]==17) { cout<< m[j] <<" " <<m17 <<endl; } if (m[j]==18) { cout<< m[j] <<" " <<m18 <<endl; } if (m[j]==19) { cout<< m[j] <<" " <<m19 <<endl; } if (m[j]==20) { cout<< m[j] <<" " <<m20 <<endl; } if (m[j]==21) { cout<< m[j] <<" " <<m21 <<endl; } if (m[j]==22) { cout<< m[j] <<" " <<m22 <<endl; } if (m[j]==23) { cout<< m[j] <<" " <<m23 <<endl; } if (m[j]==24) { cout<< m[j] <<" " <<m24 <<endl; } if (m[j]==25) { cout<< m[j] <<" " <<m25 <<endl; } if (m[j]==26) { cout<< m[j] <<" " <<m26 <<endl; } if (m[j]==27) { cout<< m[j] <<" " <<m27 <<endl; } if (m[j]==28) { cout<< m[j] <<" " <<m28 <<endl; } if (m[j]==29) { cout<< m[j] <<" " <<m29 <<endl; } if (m[j]==30) { cout<< m[j] <<" " <<m30 <<endl; } if (m[j]==31) { cout<< m[j] <<" " <<m31 <<endl; } if (m[j]==32) { cout<< m[j] <<" " <<m32 <<endl; } if (m[j]==33) { cout<< m[j] <<" " <<m33 <<endl; } if (m[j]==34) { cout<< m[j] <<" " <<m34 <<endl; } if (m[j]==35) { cout<< m[j] <<" " <<m35 <<endl; } if (m[j]==36) { cout<< m[j] <<" " <<m36 <<endl; } if (m[j]==37) { cout<< m[j] <<" " <<m37 <<endl; } if (m[j]==38) { cout<< m[j] <<" " <<m38 <<endl; } if (m[j]==39) { cout<< m[j] <<" " <<m39 <<endl; } if (m[j]==40) { cout<< m[j] <<" " <<m40 <<endl; } if (m[j]==41) { cout<< m[j] <<" " <<m41 <<endl; } if (m[j]==42) { cout<< m[j] <<" " <<m42 <<endl; } if (m[j]==43) { cout<< m[j] <<" " <<m43 <<endl; } if (m[j]==44) { cout<< m[j] <<" " <<m44 <<endl; } if (m[j]==45) { cout<< m[j] <<" " <<m45 <<endl; } if (m[j]==46) { cout<< m[j] <<" " <<m46 <<endl; } if (m[j]==47) { cout<< m[j] <<" " <<m47 <<endl; } if (m[j]==48) { cout<< m[j] <<" " <<m48 <<endl; } if (m[j]==49) { cout<< m[j] <<" " <<m49 <<endl; } if (m[j]==50) { cout<< m[j] <<" " <<m50 <<endl; } if (m[j]==51) { cout<< m[j] <<" " <<m51 <<endl; } if (m[j]==52) { cout<< m[j] <<" " <<m52 <<endl; } if (m[j]==53) { cout<< m[j] <<" " <<m53 <<endl; } if (m[j]==54) { cout<< m[j] <<" " <<m54 <<endl; } if (m[j]==55) { cout<< m[j] <<" " <<m55 <<endl; } if (m[j]==56) { cout<< m[j] <<" " <<m56 <<endl; } if (m[j]==57) { cout<< m[j] <<" " <<m57 <<endl; } if (m[j]==58) { cout<< m[j] <<" " <<m58 <<endl; } if (m[j]==59) { cout<< m[j] <<" " <<m59 <<endl; } if (m[j]==60) { cout<< m[j] <<" " <<m60 <<endl; } if (m[j]==61) { cout<< m[j] <<" " <<m61 <<endl; } if (m[j]==62) { cout<< m[j] <<" " <<m62 <<endl; } if (m[j]==63) { cout<< m[j] <<" " <<m63 <<endl; } if (m[j]==64) { cout<< m[j] <<" " <<m64 <<endl; } if (m[j]==65) { cout<< m[j] <<" " <<m65 <<endl; } if (m[j]==66) { cout<< m[j] <<" " <<m66 <<endl; } if (m[j]==67) { cout<< m[j] <<" " <<m67 <<endl; } if (m[j]==68) { cout<< m[j] <<" " <<m68 <<endl; } if (m[j]==69) { cout<< m[j] <<" " <<m69 <<endl; } if (m[j]==70) { cout<< m[j] <<" " <<m70 <<endl; } if (m[j]==71) { cout<< m[j] <<" " <<m71 <<endl; } if (m[j]==72) { cout<< m[j] <<" " <<m72 <<endl; } if (m[j]==73) { cout<< m[j] <<" " <<m73 <<endl; } if (m[j]==74) { cout<< m[j] <<" " <<m74 <<endl; } if (m[j]==75) { cout<< m[j] <<" " <<m75 <<endl; } if (m[j]==76) { cout<< m[j] <<" " <<m76 <<endl; } if (m[j]==77) { cout<< m[j] <<" " <<m77 <<endl; } if (m[j]==78) { cout<< m[j] <<" " <<m78 <<endl; } if (m[j]==79) { cout<< m[j] <<" " <<m79 <<endl; } if (m[j]==80) { cout<< m[j] <<" " <<m80 <<endl; } if (m[j]==81) { cout<< m[j] <<" " <<m81 <<endl; } if (m[j]==82) { cout<< m[j] <<" " <<m82 <<endl; } if (m[j]==83) { cout<< m[j] <<" " <<m83 <<endl; } if (m[j]==84) { cout<< m[j] <<" " <<m84 <<endl; } if (m[j]==85) { cout<< m[j] <<" " <<m85 <<endl; } if (m[j]==86) { cout<< m[j] <<" " <<m86 <<endl; } if (m[j]==87) { cout<< m[j] <<" " <<m87 <<endl; } if (m[j]==88) { cout<< m[j] <<" " <<m88 <<endl; } if (m[j]==89) { cout<< m[j] <<" " <<m89 <<endl; } if (m[j]==90) { cout<< m[j] <<" " <<m90 <<endl; } if (m[j]==91) { cout<< m[j] <<" " <<m91 <<endl; } if (m[j]==92) { cout<< m[j] <<" " <<m92 <<endl; } if (m[j]==93) { cout<< m[j] <<" " <<m93 <<endl; } if (m[j]==94) { cout<< m[j] <<" " <<m94 <<endl; } if (m[j]==95) { cout<< m[j] <<" " <<m95 <<endl; } if (m[j]==96) { cout<< m[j] <<" " <<m96 <<endl; } if (m[j]==97) { cout<< m[j] <<" " <<m97 <<endl; } if (m[j]==98) { cout<< m[j] <<" " <<m98 <<endl; } if (m[j]==99) { cout<< m[j] <<" " <<m99 <<endl; } if (m[j]==100) { cout<< m[j] <<" " <<m100 <<endl; } } return 0; } Título: Re: ayuda como puedo reducir esta codificacion Publicado por: bigfu en 17 Mayo 2010, 16:29 pm Yo lo que haria sería declarar un tipo enumerado, desde el primer numero hasta el ultimo. Creas una funcion SUC (sucesor) que te indique el siguiente enumerado, (va en el orden en el que tu lo has declarado) y lo vas metiendo en el array. Aunque no me ha quedado muy claro qué es lo que tienes que hacer, si lo puedes volver a explicar...
Título: Re: ayuda como puedo reducir esta codificacion Publicado por: Gallu en 17 Mayo 2010, 17:30 pm primero metes en un array de char todas las cadenas Código
luego usas dos bucles , y listo , lo único malo es tener que llenar el arrey de cadenas .... Código haber si te sirve Título: Re: ayuda como puedo reducir esta codificacion Publicado por: nicolasblues86 en 17 Mayo 2010, 17:34 pm siguiendo la logica que estas utilizando lo mejor seria hacer un vector de 100 elementos que inicializas con los numeros de esta manera
Código y despues haces un for de 1 a 10 y haces esta sentencia Código Entonces si el primer elemento del array que el usuario carga es un dos se imprimira el elemento 2 - 1 del array numero osea el elemento 1, es decir "dos" |