Follow me on Linkedin

Push all the zero's of a given array to the end of the array. In place only. Ex 1,2,0,4,0,0,8 becomes 1,2,4,8,0,0,0


#include<stdio.h>
#include<conio.h>
#define size 11
using namespace std;
int main()
{
    int arr[size] = {1,9,9,4,0,0,2,7,0,6,7}; 
    int current;    
    for(int j=0; j<size-1;j++)
    { 
      if(arr[j]==0)
      {
      current=j;
      break;
      }}                  
    int pos = current;  
    while( current <size )
     {   
 if( arr[current] != 0 && current != pos )
       {   
 arr[pos] = arr[current];    
 ++pos;    
 }   
 ++current;
 }  
   while( pos<size)
     {
 arr[pos] = 0;
 ++pos;
 }
    for(int i=0;i<size;i++)
    printf("%d",arr[i]);    
 getch();
 return 0;     
}
                             

a