From 3826027976b10576571d106b9e77f1f7b1825865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Javier=20Couti=C3=B1o?= Date: Sat, 24 Jan 2015 13:39:23 -0600 Subject: [PATCH] p07: Reduccion codigo... --- 07 - Primeros 10001 primos/p07 | Bin 8800 -> 8680 bytes 07 - Primeros 10001 primos/p07.cpp | 29 +++++++++++------------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/07 - Primeros 10001 primos/p07 b/07 - Primeros 10001 primos/p07 index faac25e2d396be7d187e8754590c5aca353f124d..868bed5f532eb92b8c246bf5d7964a98353f567c 100755 GIT binary patch delta 2072 zcmZuyYfMyE5I*PL-TPRCeY1eV-ZfR!%0nt_0V@yLda?efsnlO8R7=HHLv=CLlmY@x zS4tu|si`e7CT-H#^oN!|>JMBBb+Kv9+DBp^KUQ0lrPe}Q646ArGiUEbt)1k~%r`S< z&dl6<&P_BV*BxC(mklldq-;VVoJ>iG#xVsh!82+2CzWPypH!GYm%0*$IboO+3ag^q zoWn8?BExbmSBBXs`jO|%?Y|E=j#b{s$$8_cMc>U_{A{GWWTaV`q`3)OGmpcaM6MZ( z)mePGN=7q>m{c$vC>-o{i;w28h^3&bT+)c%9}QcR)!@;4CzSDYWU71xxKc}20=N5X zK|{O?ol}Vv(2~W7vCpYE$9afxpQ$LvF2q>X)M>!0ZZ$@(Y||sx_1@oRp5NRUi?&0P zJN4KY0jbAgl2l8QF^HUPwfh?gIU9uXoAjbm5PI)imL9orVBuLv$Ln=&y?~BX0)qR{ zNVbl*A{Co>6#Y$l&!462h;_;8bhO=%aXf$bGi_FlkPc@PWKQmdjkjL3z6d7z&p0-G z;i|%ZwQeeE7$#&CH_#)o*%QhFpbce9YSNQ=APi@p<@ z)(1j!0|X{3b$3paj!Offnd7%RXCv|cXon9#b!fK3&V!m}A`Zw$Zd!UFBac4b8=9d5 zp+tYw-WP_-K#hDc>MSJWLLW?vPa%2zUMj`4OXCl^K3cbh)yu9$r>O?b4;G<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A%BBrUa_(9^{LQ@aR%-EMaYN&Q9hXqU%DFS=#g z?y*wIQ$$itXrh&#Qj#jG9sDYwj3MA(Q!H1ItENP`^|V?pB^Blb>Z4wVgZ9aflgmlX oTU>JmG^=JLe9V-1ONI3oy4br2e?hyv6=^G63Da_c?#*`p2P~@EsQ>@~ diff --git a/07 - Primeros 10001 primos/p07.cpp b/07 - Primeros 10001 primos/p07.cpp index c79e4f1..0339db9 100644 --- a/07 - Primeros 10001 primos/p07.cpp +++ b/07 - Primeros 10001 primos/p07.cpp @@ -10,7 +10,7 @@ by: dbk #include -#define SIZE_ARRAY 10002 +#define SIZE_ARRAY 10001 int main(int argc, char const *argv[]) { @@ -20,46 +20,39 @@ int main(int argc, char const *argv[]) int denominador = 2; int arrayPrime[SIZE_ARRAY] = { 0 }; - bool flgEnd = false; + bool flgBuscar = true; do { - flgEnd = false; + flgBuscar = true; numerador = 1; ptrPrime = arrayPrime; do { - while(*ptrPrime != 0) + while(*ptrPrime != 0 && flgBuscar) { numerador = *ptrPrime; - if (denominador % *ptrPrime++ == 0) - { - flgEnd = true; - break; - } + flgBuscar = !(denominador % *ptrPrime++ == 0); } - if( denominador % numerador == 0 && denominador == numerador) + if( denominador % numerador == 0 && denominador == numerador ) { *ptrPrime = denominador; - flgEnd = true; + flgBuscar = false; + } + else numerador++; + + }while(flgBuscar); - numerador++; - }while(!flgEnd); denominador++; } while (arrayPrime[SIZE_ARRAY-1] == 0); - for (int i = 0; i < SIZE_ARRAY; ++i) - { - printf("%d\t-\t%d\n", i+1, arrayPrime[i]); - } - printf("El primo #%d es:\t%d\n", SIZE_ARRAY, arrayPrime[SIZE_ARRAY-1]); return 0; -- 2.0.0