top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

+7 votes
143 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 by Mona Sharma

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+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 by Vikas Upadhyay
0 votes

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 sivanraj
Similar Questions
+3 votes

Say the given string is ABC

Output should be ABC ACB BAC BCA CBA CAB

+3 votes

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

+7 votes

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

Answer

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
+5 votes

Given an unsorted array, find the max length of subsequence in which the numbers are in incremental order.

For example: If the input array is {7, 2, 3, 1, 5, 8, 9, 6}, a subsequence with the most numbers in incremental order is {2, 3, 5, 8, 9} and the expected output is 5.

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...