用visual studio 2015写c++程序显示“语法错误 应输入表达式”如何解决?
#include<iostream>#include<string>usingnamespacestd;intmain(){intarray[]={3,14,27,31,...
#include <iostream>#include <string>using namespace std;int main(){ int array[] = { 3,14,27,31,39,42,55,70,74,81,85,93,98 }; int size = sizeof(array); int key; cout << "寻找的数:" << endl; cin >> key; BinarySearch(array[],size, key); system("pause"); return 0;}int BinarySearch(int a[],int n,int k){ int l = 0, r = n - 1; int m; while (l <= r) { m = (l + r) / 2; if (k == a[m]) { cout << "第" << m << "个" << endl; return m; } else if (k < a[m]) r = m - 1; else l = m + 1; } return -1;}
展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询