# Push all the zero’s of a given array to the end of the array.

147 views

Given an array of random numbers, Push all the zero’s of a given array to the end of the array.

posted Oct 29, 2013

+1 vote
``````void PushZero(int *array, int n)
{
int no = 0;
for (int i = 0; i < n; i++)
if (array[i] != 0)
array[no++] = array[i];

while (no < n)
array[no++] = 0;
}
``````

Replace 0 with next number and Count no of 0.
Now assign zeros in last.

answer Oct 29, 2013

let I point first value and J point last value.

i++, j--
condition goes until hit i>=j

swap I and J, if I ==0

answer Oct 29, 2013 by
Similar Questions

Say the given string is `ABC`

Output should be `ABC` `ACB` `BAC` `BCA` `CBA` `CAB`

Please help me to print all permutations of a string in C?

You have a 2D matrix. Only two ZEROs in matrix.
Find the path from 1st zero to 2nd zero with least sum.

``````1       6       8       9       0       3

4       9       -5      5       11      13

8       9       44      23      15      -20

7       9       7       -13     14      11

0       16      23      31      16      7

67      5       4       23      21      19
``````

``````1       6       8       9       0  ----> 3
|
4       9       -5      5       11      13
|
8       9       44      23      15      -20
|
7 <---- 9 <---- 7 <--- -13 <--- 14 <---  11
|
0       16      23      31      16        7

67      5       4       23      21       19
``````