# Thread: C: Find longest series of even and positive numbers

1. ## C: Find longest series of even and positive numbers

Hi.

I need help with this program:

Example input: 2 4 6 -1 7 3 -2 1
Output: 3 3 (longest series of even is 3, longest series of positive is 3)

Here is the code:

Code:
```#include <stdio.h>
int even(int x)
{
return x % 2 == 0;
}

int positive(int x)
{
return x>0;
}
int longest_series(int a[], int n, int (*f) (int)) {
int i;
/*Length of the current series is  0 or  1 depending on whether it is a array
empty or not*/
int cs = 0;
/* Longest series is current series */
int ls = cs;
for (i = 0; i < n; i++) {
if ((*f)(a[i]))
cs++;
else
cs = 0;
if (cs > ls)
ls = cs;
}
return ls;
}
int main() {
int a[] = {2,4,6,-1,7,3,-2,1},
n = sizeof(a)/sizeof(int);
printf("%d %d\n", longest_series(a, n, &even),
longest_series(a, n, &positive));
return 0;
}```
My question is how to write this code if the prototype of function is:

Code:
`void series(int *array, int n, int (*s)(int), int **begining, int *lenght);`
Thanks for replies.