Is A Number A Prime?
The formula below will test the number in cell C9 and return the word prime if it is prime or the string not prime if the number is not prime.
IF(C9=2,"Prime",IF(AND(MOD(C9,ROW(INDIRECT("2:"&ROUNDUP(SQRT(C9),0))))<>0),"Prime","Not Prime"))
This is an array formula, so you must press CTRL SHIFT ENTER rather than just ENTER when you first enter the formula and whenever you edit it later. If you do this properly, Excel will display the formula enclosed in curly braces { }. See the array formulas page for much more detail about array formulas. Note that the formula will not work properly if you do not enter it with CTRL SHIFT ENTER. This formula will work with numbers up to 268,435,455, after which Excel's ability to handle the intermediate array fails.
No comments:
Post a Comment