**Code:**
short factor(long factand) { if(factand <= 1) { return factand; } else { short divisor; bool isfactor = false; for(divisor = 2;!isfactor;divisor++) { isfactor = (factand%divisor==0); } return divisor-1; } }
//------------------------------------------------------------------------------------------------------------------------//
task main() { string factorization; string nextfactor; short numtofactor = 30;// Change this number if you like. It's the number this code factorizes. while(factor(numtofactor)>1) { factorization = factorization + "*"; StringFormat(nextfactor,"%d",factor(numtofactor)); factorization = factorization + nextfactor; numtofactor /= factor(numtofactor); } StringDelete(factorization,0,1); nxtDisplayCenteredTextLine(3,"%s",factorization); while(nNxtButtonPressed == -1){} } |