fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr[] = {0,2,0,5,0,0,7,0};
  6. int n = 8;
  7. int removed = 0;
  8. for (int i=0;i<n;i++)
  9. {
  10. if (arr[i]==0)
  11. removed++;
  12. else
  13. arr[i-removed] = arr[i];
  14. }
  15. n -= removed;
  16. if (n==0)
  17. printf("NO");
  18. else
  19. for (int i=0;i<n;i++)
  20. printf("%d ", arr[i]);
  21. return 0;
  22. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
2 5 7