A C++ interview question

來源: haomeili 2007-07-17 20:54:57 [] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (403 bytes)
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

請您先登陸,再發跟帖!

發現Adblock插件

如要繼續瀏覽
請支持本站 請務必在本站關閉/移除任何Adblock

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

安裝Adblock plus用戶請點擊瀏覽器圖標
選擇“Disable on www.wenxuecity.com”

安裝Adblock用戶請點擊圖標
選擇“don't run on pages on this domain”