读入20个无序整型数据,然后再读入一个整型数x,判断x是否存在于读入的20个数据中,若存在则输出Found,Pos=x(x为具体下标值),若不存在则输出No found的提示信息
#include <iostream>
using namespace std;
#define N 20
int main() {
int a[N], i, x;
cout << "Input " << N << " datas:";
for (i = 0; i < N; i++)
cin >> a[i];
cout << "Input x:";
cin >> x;
for (i = 0; i < N; i++)
if (x == a[i])
break;
if (i < N)
cout << "Found. Pos=" << i << endl;
else
cout << "No found" << endl;
return 0;
}