1. Please, give your answers in comments – what does the function written below do:

a) recognizes prime numbers

b) recognizes prime numbers in interval [100;999]

c) neither a) nor b) is correct

d) other variant (please, specify)

2. And the second question is – is this function a correct solution if the task is as follows: `Please, write a function that recognizes all the prime numbers consisting of exactly 3 digits`:

a) yes

b) no

The function (in C++):

bool f(int x) {

for (int y=2;y<x;y++)

if (x%y==0) return false;

return true;

}

P.S. I wish all of you wrote your thoughts in order to make a student of mine understand the essence of the thing!

### Like this:

Like Loading...

*Related*

1: d) prime numbers and prime numbers (100,999), because there is no exception that would allow to get all prime numbers except those from 100 to 999.

2: The actual question to the task was to “create function that recognises prime numbers from 3 digits”. There was no word for “exactly”, saying the function has to be limited from 100 to 999.

But answer to your question here is: b) no, it does not.

OK, but it is quite understandable – if there is said that the function must recognize 3-digital prime numbers, then it is not done with no purpose 😉

Then, you could notice it was not said the function must recognize EXACTLY prime numbers 😉 And so you could offer a function recognizing every integer as a correct solution 😀

bool f(int x) {return true;}

My solution involved creating all prime numbers recognising function with limiting input to numbers from 100 to 999.

so:

do i check numbers with 3 digits? yes

does function check 3 digit numbers? yes

problem solved.

Exactly – like you said, your solution was a function recognizing all prime numbers that is not correct (or what is as correct as a function recognizing all integers).

Whether or not you did other part of the whole task, it is a different talk (but if we talk about it, I have to admit the other part was correct, so you got half of a score overall).

Vecais labais php. Ko vēl pastāstīt