It determines the location index of a number k.
If I use vector instead of array, is there a function that can do that?Code:#include <iostream> using namespace std; int main() { int a[1024], k, x, i, flag; unsigned int n; cin >> k >> n; for ( i = 0; i < n; i++ ) { cin >> x; a[i] = x; } for ( i = 0; i < n; i++ ) { if ( a[i] == k ) { flag = i; break; } else flag = -1; } cout << flag <<endl; }