Advertisement
AntonStanoev

6

Apr 3rd, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | Source Code | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     int n;
  5.     printf("Enter the length of the row: ");
  6.     scanf("%d", &n);
  7.  
  8.     int arr[n];
  9.     printf("Enter the row of numbers:\n");
  10.     for (int i = 0; i < n; i++) {
  11.         scanf("%d", &arr[i]);
  12.     }
  13.  
  14.     int start = 0, end = 0, max_len = 1, curr_len = 1;
  15.     for (int i = 1; i < n; i++) {
  16.         if (arr[i] > arr[i - 1]) {
  17.             curr_len++;
  18.             if (curr_len > max_len) {
  19.                 max_len = curr_len;
  20.                 end = i;
  21.                 start = end - max_len + 1;
  22.             }
  23.         } else {
  24.             curr_len = 1;
  25.         }
  26.     }
  27.  
  28.     printf("The longest increasing underrow is: ");
  29.     for (int i = start; i <= end; i++) {
  30.         printf("%d ", arr[i]);
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement