Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. /**
  2. * Finds the longest sequence out of every array and then returns the longest between them
  3. * @param    int* arrays[]        - an array that holds the addresses of the array to be checked
  4. * @param    int  arrays_length[] - an array that holds the lengths (sizes) of the arrays addresses
  5. * @param    int  size            - size of the pointer arrays
  6. * @returns  int                  - longest positive sequence found;0 if none
  7. */
  8. int getLongestSequenceFromArrays(int* arrays[], int arrays_length[], int size)
  9. {
  10.     int i, *j,
  11.         currentSequence, maxSequence = 0;
  12.  
  13.     for (i = 0; i < size; i++)
  14.     {
  15.         currentSequence = 0;
  16.  
  17.         for (j = arrays[i]; j < arrays[i] + arrays_length[i]; j++)
  18.             if (*j > 0)
  19.             {
  20.                 currentSequence++;
  21.                 if (currentSequence > maxSequence)
  22.                     maxSequence = currentSequence;
  23.             }
  24.             else
  25.                 currentSequence = 0;
  26.     }
  27.     return maxSequence;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement