<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://gentoo-zh.org/extern.php?action=feed&amp;tid=392&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Gentoo-zh / C 练习实例83]]></title>
		<link>http://www.gentoo-zh.org/viewtopic.php?id=392</link>
		<description><![CDATA[C 练习实例83 最近发表的帖子。]]></description>
		<lastBuildDate>Mon, 29 Aug 2022 11:49:00 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[C 练习实例83]]></title>
			<link>http://www.gentoo-zh.org/viewtopic.php?pid=398#p398</link>
			<description><![CDATA[<p>题目：求0—7所能组成的奇数个数。</p><p>程序分析：</p><p>这个问题其实是一个排列组合的问题，设这个数为 sun=a1a2a3a4a5a6a7a8,a1-a8 表示这个数的某位的数值，当一个数的最后一位为奇数时，那么这个数一定为奇数，不管前面几位是什么数字。如果最后一位数为偶数，则这个数一定为偶数。</p><p>a1-a8可以取 0-7 这个八个数字，首位数字不为 0。</p><p>从该数为一位数到该数为8位数开始统计奇数的个数：</p><p>&#160; &#160; 1.当只有一位数时也就是该数的最后一位，奇数个数为4<br />&#160; &#160; 2.当该数为两位数时，奇数个数为4*7=28<br />&#160; &#160; 3.当该数为三位数时，奇数个数为：4*8*7=224<br />&#160; &#160; ...<br />&#160; &#160; 8.当该数为八位数时，奇数个数为：4*8*8*8*8*8*8*7(依次为最后一位到第一位)</p><div class="codebox"><pre><code>#include&lt;stdio.h&gt;
int main(int agrc, char*agrv[])
{
    long sum = 4, s = 4;//sum的初始值为4表示，只有一位数字组成的奇数个数为4个
    int j;
    for (j = 2; j &lt;= 8; j++)
    {    
        printf(&quot;%d位数为奇数的个数%ld\n&quot;, j-1, s);
        if (j &lt;= 2)
            s *= 7;
        else
            s *= 8;
        sum += s;    
    }
    printf(&quot;%d位数为奇数的个数%ld\n&quot;, j-1, s);
    printf(&quot;奇数的总个数为：%ld\n&quot;, sum);
    // system(&quot;pause&quot;);
    return 0;
}</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (batsom)]]></author>
			<pubDate>Mon, 29 Aug 2022 11:49:00 +0000</pubDate>
			<guid>http://www.gentoo-zh.org/viewtopic.php?pid=398#p398</guid>
		</item>
	</channel>
</rss>
