c02p107a.txt

来自「Data Abstraction & Problem Solving with 」· 文本 代码 · 共 36 行

TXT
36
字号
// Exercise 12int search(int first, int last, int n);int mystery(int n);int main(){   cout << mystery(30) << endl;   return 0;}  // end mainint search(int first, int last, int n){   int returnValue;   cout << "Enter: first = " << first << " last = "        << last << endl;   int mid = (first + last)/2;   if ( (mid * mid <= n) && (n < (mid+1) * (mid+1)) )      returnValue = mid;   else if (mid * mid > n)      returnValue = search(first, mid-1, n);   else      returnValue = search(mid+1, last, n);   cout << "Leave: first = " << first << " last = "        << last << endl;   return returnValue;}  // end searchint mystery(int n){   return search(1, n, n);}  // end mystery

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?