A C++ interview question

Write a C++/C function which prints out prime integers, i.e., given an input X, print out all its prime numbers. For example,

if X=20, prime elements will be: 1, 2, 3, 5, 7, 9, 11, 13, 17, 19.
If X= 100, primes are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.


void (int X)
{
???????
???????
}


Thanks.

所有跟帖: 

Correction: 回复:A C++ interview question -haomeili- 给 haomeili 发送悄悄话 haomeili 的博客首页 (200 bytes) () 07/17/2007 postreply 20:57:04

回复:1 is a prime number? I don't think so! -鸡毛蒜皮- 给 鸡毛蒜皮 发送悄悄话 鸡毛蒜皮 的博客首页 (0 bytes) () 07/18/2007 postreply 11:19:35

这是一个数学问题,算法不难, 不像interview能遇到的 -MGM- 给 MGM 发送悄悄话 (313 bytes) () 07/17/2007 postreply 21:28:24

last line should be: if is_prime then print i -MGM- 给 MGM 发送悄悄话 (0 bytes) () 07/17/2007 postreply 21:30:26

回复:A C++ interview question -上中下- 给 上中下 发送悄悄话 (370 bytes) () 07/17/2007 postreply 22:16:54

"if round i/j=0, i=i-1, count=0;" 这里递减i的值是不对的 -MGM- 给 MGM 发送悄悄话 (0 bytes) () 07/17/2007 postreply 22:50:12

你数学怎么学的?! -连续工作- 给 连续工作 发送悄悄话 (58 bytes) () 07/18/2007 postreply 04:49:14

你这么凶把女孩子们都吓跑了... -德州女孩- 给 德州女孩 发送悄悄话 (0 bytes) () 07/18/2007 postreply 06:49:26

你也强不到哪里去 -德州老外- 给 德州老外 发送悄悄话 德州老外 的博客首页 (19 bytes) () 07/18/2007 postreply 19:56:49

请您先登陆,再发跟帖!