Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int b, n, index=0;
- cout << "How many numbers will you check: "<<endl;
- cin >> n;
- int* a;
- a = new int[n];
- cout << "What is the element you want to check: "<<endl;
- cin >> b;
- for (int i = 0; i < n; i++) { //loop for element input
- cout << "Enter an element: " << endl;
- cin >> a[i];
- }
- for (int i = 0; i < n; i++) {//loop for checking the key element
- if (a[i] == b) {
- index = i;
- break;
- }
- }
- cout << "The element appears for the first time at number: " << index + 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment