fork download
  1. #include <stdio.h>
  2.  
  3. void addZerosAt(int * a, int N, int p1, int p2)
  4. {
  5. if (p1 > p2)
  6. {
  7. int p = p1;
  8. p1 = p2;
  9. p2 = p;
  10. }
  11. for(int i = N+1; i >= p1; --i)
  12. {
  13. if (i > p2) a[i] = a[i-2];
  14. else a[i] = a[i-1];
  15. }
  16. a[p1] = a[p2] = 0;
  17. }
  18.  
  19.  
  20. int main(int argc, const char * argv[])
  21. {
  22. int a[20] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
  23. for(int i = 0; i < 15; ++i) printf("%2d ",a[i]); puts("");
  24. addZerosAt(a,15,5,12);
  25. for(int i = 0; i < 17; ++i) printf("%2d ",a[i]); puts("");
  26. }
  27.  
Success #stdin #stdout 0s 4792KB
stdin
Standard input is empty
stdout
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 
 1  2  3  4  5  0  6  7  8  9 10 11  0 12 13 14 15