Let the array contain the input sequence of numbers. The numbering of the array elements starts from 0. The array contains numbers. The element has two neighbors if only 1 \leq i \leq n – 1.
To count the number of elements that are greater than their two neighbors, it is necessary to iterate through all such that 1 \leq i \leq n – 1, and check the fulfillment of two conditions: m[i - 1] < m[i] and m[i] > m[i + 1].
Declare the working array.
int m[101];Read the number of input numbers .
scanf("%d", &n);Read the input array.
for (i = 0; i < n; i++)
scanf("%d", &m[i]);In the variable res, count the number of elements that are greater than their two neighbors.
res = 0;Iterate through all such that 1 \leq i \leq n – 1 and check the fulfillment of two conditions: m[i - 1] < m[i] and m[i] > m[i + 1].
for (i = 1; i < n - 1; i++)
if (m[i] > m[i - 1] && m[i] > m[i + 1]) res++;Output the answer.
printf("%d\n", res);