close
標題:

大於100且小於900的整數中,其平方根為整數的有幾個???

發問:

aa.jpg

 

此文章來自奇摩知識+如有不便請留言告知

請問大於100且小於900的整數中,其平方根為整數的有幾個??? 謝謝!!!

最佳解答:

參考.. #include #include int main() { int i=1, cnt=0; while(i*i<=100) ++i; while(i*i<900) { ++cnt; printf("%d : %d(%d*%d) ", cnt, i*i, i, i); ++i; } printf("Total : %d ", cnt); system("pause"); return 0; } --- 執行結果: 1 : 121(11*11) 2 : 144(12*12) 3 : 169(13*13) 4 : 196(14*14) 5 : 225(15*15) 6 : 256(16*16) 7 : 289(17*17) 8 : 324(18*18) 9 : 361(19*19) 10 : 400(20*20) 11 : 441(21*21) 12 : 484(22*22) 13 : 529(23*23) 14 : 576(24*24) 15 : 625(25*25) 16 : 676(26*26) 17 : 729(27*27) 18 : 784(28*28) 19 : 841(29*29) Total : 19 2012-01-19 14:28:21 補充: 對唷, 忘了這麼做會比較快,感謝 帕拉提斯 提醒。

其他解答:

這... 我想... 應該不用去判斷 i*i <= 100, 將 100 開根號 = 10、900 開根號 = 30,所以跑 (10+1) ~ (30-1) ,就好了... 現代的 CPU,開根號是 O(1)...D4CDE60C03A2F1BC
arrow
arrow

    ddhdxb5 發表在 痞客邦 留言(0) 人氣()