#include <stdio.h>
int upper(int a[], int n, int x)
{
int lo = 0, hi = n - 1, mid;
while (lo < hi)
{
mid = (lo + hi + 1) / 2;
if (a[mid] <= x)
lo = mid;
else
hi = mid - 1;
}
return lo;
}
int lower(int a[], int n, int x)
{
int lo = 0, hi = n - 1, mid;
while (lo < hi)
{
mid = (lo + hi) / 2;
if (a[mid] >= x)
hi = mid;
else
lo = mid + 1;
}
return lo;
}
int main(int argc, char *argv[])
{
int a[] = {1, 2, 2, 2, 3};
int n = sizeof(a)/sizeof(a[0]);
printf("upper bound:%d\nlower bound:%d\n", upper(a, n, 2) , lower(a, n, 2));
return 0;
}