fork download
  1. #include <stdio.h>
  2.  
  3. int calculate(int *arr, int size) {
  4. if (size <= 0) return 0;
  5. if (size == 1) return *arr;
  6.  
  7. int mid = size / 2;
  8. int left = calculate(arr, mid);
  9. int right = calculate(arr + mid, size - mid);
  10.  
  11. int *ptr = arr;
  12. for (int i = 0; i < size; i++) {
  13. *ptr = (*ptr + i) % 3 == 0 ? left : right;
  14. ptr++;
  15. }
  16.  
  17. return *(arr + size - 1);
  18. }
  19.  
  20. int main() {
  21. int values[4] = {2, 4, 6, 8};
  22. int result = calculate(values, 4);
  23. printf("%d %d %d %d %d\n", values[0], values[1], values[2], values[3], result);
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
6 6 6 4 4