#include <stdio.h>
int main()
{
int arr[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
int first, last, start, end, mid, x;
start = 0;
end = 9;
first = last = -1;
while (start <= end) {
mid = start + (end - start) / 2;
if (arr[mid] == x) {
first = mid;
end = mid - 1;
} else if (arr[mid] <= x) {
start = mid + 1;
} else {
end = mid - 1;
}
}
start = 0;
end = 9;
while (start <= end) {
mid = start + (end - start) / 2;
if (arr[mid] == x) {
last = mid;
start = mid + 1;
} else if (arr[mid] < x){
start = mid + 1;
} else {
end = mid - 1;
}
}
if (last != -1)
printf("The number of occurance is %d\n", last
- first
+ 1); else
printf("The number of occurance is 0\n"); return 0;
}