Advertisement
Josif_tepe

Untitled

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