Advertisement
yasenst

Zadacha 6

May 22nd, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define N 5
  5.  
  6. int f(int *arr, int *max)
  7. {
  8.     int i, current = 1, res = 0;
  9.     for (i = 1; i < N; i++)
  10.     {
  11.         if (arr[i] < arr[i-1])
  12.             current ;
  13.         else
  14.         {
  15.             if (current > 1)
  16.             {
  17.                 res ++;
  18.                 printf("The sequence is long %d\n", res , current );
  19.                 if (current  > (*max))
  20.                     *max= current ;
  21.             }
  22.            
  23.             current = 1;
  24.         }
  25.     }
  26.     if (current > 1)
  27.         {
  28.             res ++;
  29.             printf("The sequence is long %d\n", res , current );
  30.  
  31.             if (current  > (*max))
  32.                 *max= current ;
  33.         }
  34.  
  35.     return res;
  36. }
  37.  
  38. int main()
  39. {
  40.     int arr[N] = {5, 1, 9, 6, 4};
  41.  
  42.     int max = 0;
  43.  
  44.     int count = f(arr, &max);
  45.     printf("all sequences are %d, the longest is %d\n", count, max);
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement