Using recursion (and not a loop), define function anyFactor(n,i,j), which yields true if one of the numbers i, i+1, ... j is a factor of n. (More precisely, it returns true if there is a factor k of n where ikj.)

After defining anyFactor, define isPrime as by saying that n is prime is it does not have any factor from 2 to n-1. Add an Execute part that does some tests of isPrime.

Hint.

  1. anyFactor(n,i,j) is always false when i > j, because then there are no numbers k at all that satisfy i < kj, let alone any that are factors of n.

  2. Otherwise, if i is a factor of n, then there certainly is a factor of n in that range.

  3. What should you do in the case where ij and i is not a factor of n?

 

    [Language: Cinnameg  Kind: program]