c - loop not running as intended -


i can't find break in logic here when run output of 3125 supposed largest prime factor. 3125 not prime nor largest non-prime factor. not designed efficient method find prime factors, trying figure out.

long long modulo= 99999; long long lrgprimefactor=0; long long currentfactor=0; long long tempmodulo=0; int break1 =0; int break2 =0;  while (modulo>0&&break2==0) {     if ((100000%modulo) ==0)     {         currentfactor=modulo;          (tempmodulo=currentfactor-1;tempmodulo>0;tempmodulo--)         {             if (currentfactor%tempmodulo==0)             {                 lrgpfactor=currentfactor;                 break1=1;                 break;             }             else if(break1==1)             {                 break2=1;                 break;             }         }     }     else      {         modulo-=2;     } } 

i made changes code, , gives correct result. hope helps.

long long modulo = 99999; long long lrgpfactor = 0; long long currentfactor = 0; long long tempmodulo = 0;  while (modulo > 0) {     if (100000 % modulo == 0)     {         (tempmodulo = modulo - 1; tempmodulo > 1; --tempmodulo)         {             if (modulo % tempmodulo == 0)                 break;         }         if (tempmodulo == 1)         {             lrgpfactor = modulo;             break;         }     }     modulo -= 2; } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -