A better approach would be simple: sort the array - C includes the
C library function - qsort()[
^] which will help you with that.
Once sorted, all identical values are side by side - so counting identical values becomes trivial - a single pass through the sorted array will identify all values whose count equals their value.
Then it's trivial: when you identify a value as matching your condition count it, and add it to a total.
After the loop you can decide what to print and calculate the average from the count and total.
And do yourself a favour: stop using single character variable names: use names that describe what their function is:
count
instead of
b
(or possibly
m
?),
total
instead of ... well, to be honest I'm not what your total is called ... and I'm not convinced you know either looking at that code.
It makes your code more readable, and that means more reliable.