Advertisement
Josif_tepe

Untitled

Jan 20th, 2024
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. void funkcija(int * niza, int n) {
  7.     int prev_element = niza[0];
  8.     int nova_niza[n];
  9.     nova_niza[0] = niza[0];
  10.     int j = 1;
  11.     for(int i = 1; i < n; i++) {
  12.         if(prev_element <= niza[i]) {
  13.             nova_niza[j] = niza[i];
  14.             prev_element = niza[i];
  15.             j++;
  16.         }
  17.     }
  18.     for(int i = 0; i < j; i++) {
  19.         printf("%d ", nova_niza[i]);
  20.     }
  21. }
  22. int main(int argc, const char * argv[]) {
  23.     int n;
  24.     scanf("%d", &n);
  25.  
  26.     int niza[n];
  27.     for(int i = 0; i < n; i++) {
  28.         scanf("%d", &niza[i]);
  29.     }
  30.     funkcija(niza, n);
  31.     return 0;
  32. }
  33.  
  34.  
  35. /*
  36. 8
  37. 1 2 -1 -2 4 3 15  7  2
  38. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement