fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void newarray(int *X, int n)
  6. {
  7. int j = 0;
  8. for (int i = 0; i < n; i++)
  9. if (X[i] > 0) X[j++] = X[i];
  10. for(; j < n; X[j++] = 0);
  11. }
  12.  
  13. int main(int argc, char * argv[])
  14. {
  15. int X[10] = { 5, 2, -1, 0, -4, 8, 1, 3, -10, 0 };
  16. for (int i = 0; i < 10; i++)
  17. cout << X[i] << ' ';
  18. cout << endl;
  19. newarray(X,10);
  20. for (int i = 0; i < 10; i++)
  21. cout << X[i] << ' ';
  22. cout << endl;
  23. }
  24.  
  25.  
Success #stdin #stdout 0.01s 5420KB
stdin
Standard input is empty
stdout
5 2 -1 0 -4 8 1 3 -10 0 
5 2 8 1 3 0 0 0 0 0