fork(2) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int a[] = {2, 0, 3, 4, 0, 0, 8};
  8. const size_t n = sizeof a / sizeof (int);
  9. size_t i;
  10.  
  11. for (size_t q=i=0; q<n; ++q)
  12. if (a[q])
  13. a[i++] = a[q];
  14.  
  15. for (; i<n; ++i)
  16. a[i] = 0;
  17.  
  18. for (size_t q=0; q<n; ++q)
  19. cout << a[q] << ' ';
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
2 3 4 8 0 0 0