What Does This Function Do?

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!

Random Number Generator – As Easy As 01, 10, 11..

Someone told me it is not a trivial task to make a good function generating a random number. What a fool I was to believe him! It turns out you can write down the function very easily. For example, in C++:

int getRandomNumber() {

   return 3; // proven to be random – obtained by throwing a dice


Not too complicated function, eh?

Published in: on Thursday, January 10, 2008 at 6:50 pm  Comments (2)  
Tags: , , , , , , , , ,