<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Moving Zeros To The End Archives - Onestring Lab</title>
	<atom:link href="https://onestringlab.com/tag/moving-zeros-to-the-end/feed/" rel="self" type="application/rss+xml" />
	<link>https://onestringlab.com/tag/moving-zeros-to-the-end/</link>
	<description>Kode Kreativitas Kopi</description>
	<lastBuildDate>Mon, 04 May 2026 08:37:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://onestringlab.com/wp-content/uploads/2021/10/cropped-osl-high-res-e1455499003866-32x32.jpg</url>
	<title>Moving Zeros To The End Archives - Onestring Lab</title>
	<link>https://onestringlab.com/tag/moving-zeros-to-the-end/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Belajar Bahasa C &#8211; Moving Zeros To The End</title>
		<link>https://onestringlab.com/moving-zeros-to-the-end/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Mon, 05 Dec 2022 02:00:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Moving Zeros To The End]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=821</guid>

					<description><![CDATA[<p>Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements. The problem &#8230; </p>
<p>The post <a href="https://onestringlab.com/moving-zeros-to-the-end/">Belajar Bahasa C &#8211; Moving Zeros To The End</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements. The problem link is <a href="http://bit.ly/3B9KKJj" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p><strong>Examples</strong>:</p>



<pre class="wp-block-code"><code lang="csharp" class="language-csharp">move_zeros(10, int [] {1, 2, 0, 1, 0, 1, 0, 3, 0, 1}); // -&gt; int [] {1, 2, 1, 1, 3, 1, 0, 0, 0, 0}</code></pre>



<p><strong>Sample Tests:</strong></p>



<pre class="wp-block-code"><code lang="csharp" class="language-csharp">Test(move_zeros, sample_tests) {
    do_test(8, ((int []) {0, 1, 0, 2, 0, 3, 4, 5}), ((int []) {1, 2, 3, 4, 5, 0, 0, 0}));
    do_test(20, ((int []) {9, 0, 0, 9, 1, 2, 0, 1, 0, 1, 0, 3, 0, 1, 9, 0, 0, 0, 0, 9}), ((int []) {9, 9, 1, 2, 1, 1, 3, 1, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
    do_test(2, ((int []) {0, 0}), ((int []) {0, 0}));
    do_test(1, ((int []) {0}), ((int []) {0}));
    do_test(0, ((int []) {}), ((int []) {}));
}</code></pre>



<p><strong>Solution:</strong></p>



<pre class="wp-block-code"><code lang="csharp" class="language-csharp line-numbers">#include &lt;stddef.h&gt;

void move_zeros(size_t len, int arr[len])
{
  // mutate arr in place
  size_t i, j, k, temp;
  for (i = 0; i &lt; len; i++)
  {
    if (arr[i] == 0)
    {
      k = i;
      for (j = i + 1; j &lt; len; j++)
      {
        if (arr[j] != 0)
        {
          temp = arr[j];
          arr[j] = 0;
          arr[k] = temp;
          k = j;
        }
      }
    }
  }
}
</code></pre>
<p>The post <a href="https://onestringlab.com/moving-zeros-to-the-end/">Belajar Bahasa C &#8211; Moving Zeros To The End</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
