Previous Next
0 / 21
Module DEMO-32-106DEMO-C-32

Move Zeros to End

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a C program to move all zeros in a 1D array to the end while maintaining the relative order of the non-zero elements.

Example

Input:

5 0 1 0 3 12

Output:

1 3 12 0 0

Constraints

1 <= n <= 100

Input Format

n and array

Output Format

Array with zeros at end

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
5
0 1 0 3 12
1 3 12 0 0
Two zeros moved to end.
Sample #2
Public sample
3
0 0 0
0 0 0
All zeros.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings