#include <iostream>
using namespace std;
int main () {
int array[10];
cout << "enter elements of array: \n";
for (int i = 0; i < 10; i++) {
cout << "array[" << i << "] = ";
cin >> array[i];
}
cout << "The array: ";
for (int i = 0; i < 10; i++) {
cout << array[i] << " ";
}
int occurance = 0, search, index;
cout << "\nEnter searched element: "; cin >> search;
for (int i = 0; i < 10; i++) {
if (search == array[i]) {
occurance++;
}
}
if (occurance == 2) {
for (int i = 9; i >= 0; i--) {
if (array[i] == search) {
array[i] = -1;
index = i;
break;
}
}
cout << "The index of searched element in a second time is " << index << endl;
cout << "modified array: ";
for (int i = 0; i < 10; i++) {
cout << array[i] << " ";
}
}
else {
cout << "The number of occurance of the " << search << " is " << occurance << endl;
}
}
Comments
Leave a comment