Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define N 5
- int f(int *arr, int *max)
- {
- int i, current = 1, res = 0;
- for (i = 1; i < N; i++)
- {
- if (arr[i] < arr[i-1])
- current ;
- else
- {
- if (current > 1)
- {
- res ++;
- printf("The sequence is long %d\n", res , current );
- if (current > (*max))
- *max= current ;
- }
- current = 1;
- }
- }
- if (current > 1)
- {
- res ++;
- printf("The sequence is long %d\n", res , current );
- if (current > (*max))
- *max= current ;
- }
- return res;
- }
- int main()
- {
- int arr[N] = {5, 1, 9, 6, 4};
- int max = 0;
- int count = f(arr, &max);
- printf("all sequences are %d, the longest is %d\n", count, max);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement