#include <iostream>
void find_first_and_Last_position(int arr[], int len, int n, int *first, int *last) {
*first = -1, *last = -1;
for (int i = 0; i < len; i++) {
if (n != arr[i])
continue;
if (*first == -1)
*first = i;
*last = i;
}
}
int main() {
int arr[] = { 1, 3, 7, 8, 3, 1, 9 };
int first, last;
int n = 3;
find_first_and_Last_position(arr, sizeof(arr)/sizeof(int), n, &first, &last);
if (first != -1)
std::cout << "First positions = " << first << " Last positions = " << last;
else
std::cout << "Not found";
}
/*
run:
First positions = 1 Last positions = 4
*/