2014년 12월 2일 화요일

Cannot set of prime numbers

What is wrong with this code? Cannot print prime numbers from given interval.
Please help......




see the tips provided in your other thread https://groups.google.com/d/msg/mitappinventortest/noD-DZteQA0/k87_lI8MveMJ
it seems to be, you did not try anything?



You are asking a single procedure to do two contradictory things - 
  1. test ALL numbers up to a given maximum if they are prime numbers
  2. return a single prime/not prime result.
What you should to is take the inner loop of your procedure 
and move it into a new return procedure that will test just a single number
for its prime quality, returning true or false.
Call the return procedure IsThisAPrime, for example.

For your button procedure, where you want to see ALL the primes,
move that outer loop and call the IsThisAPrime procedure on each
prime candidate, appending the winners to your output text field.


댓글 없음:

댓글 쓰기