#include <stdio.h>
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(void)
{
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)
printf("First positions = %d Last positions = %d\n", first, last);
else
printf("Not found\n");
return 0;
}
/*
run:
First positions = 1 Last positions = 4
*/