<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://www.gentoo-zh.org/extern.php?action=feed&amp;tid=312&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Gentoo中文社区 / C 练习实例3]]></title>
		<link>https://www.gentoo-zh.org/viewtopic.php?id=312</link>
		<description><![CDATA[C 练习实例3 最近发表的帖子。]]></description>
		<lastBuildDate>Mon, 29 Aug 2022 06:56:35 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[C 练习实例3]]></title>
			<link>https://www.gentoo-zh.org/viewtopic.php?pid=318#p318</link>
			<description><![CDATA[<p>题目：一个整数，它加上100后是一个完全平方数，再加上168又是一个完全平方数，请问该数是多少？</p><p>程序分析：</p><p>假设该数为 x。</p><p>1、则：x + 100 = n2, x + 100 + 168 = m2</p><p>2、计算等式：m2 - n2 = (m + n)(m - n) = 168</p><p>3、设置： m + n = i，m - n = j，i * j =168，i 和 j 至少一个是偶数</p><p>4、可得： m = (i + j) / 2， n = (i - j) / 2，i 和 j 要么都是偶数，要么都是奇数。</p><p>5、从 3 和 4 推导可知道，i 与 j 均是大于等于 2 的偶数。</p><p>6、由于 i * j = 168， j&gt;=2，则 1 &lt; i &lt; 168 / 2 + 1。</p><p>7、接下来将 i 的所有数字循环计算即可。</p><p>具体实现如下：</p><br /><br /><p>#include &lt;stdio.h&gt;</p><p>int main (void)<br />{<br />&#160; &#160; int&#160; i, j, m, n, x;<br />&#160; &#160; for (i = 1; i &lt; 168 / 2 + 1; i++)<br />&#160; &#160; {<br />&#160; &#160; &#160; &#160; if (168 % i == 0)<br />&#160; &#160; &#160; &#160; {<br />&#160; &#160; &#160; &#160; &#160; &#160; j = 168 / i;<br />&#160; &#160; &#160; &#160; &#160; &#160; if ( i &gt; j &amp;&amp; (i + j) % 2 == 0 &amp;&amp; (i - j) % 2 == 0)<br />&#160; &#160; &#160; &#160; &#160; &#160; {<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; m = (i + j) / 2;<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; n = (i - j) / 2;<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; x = n * n - 100;<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; printf (&quot;%d + 100 = %d * %d\n&quot;, x, n, n);<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; printf (&quot;%d + 268 = %d * %d\n&quot;, x, m, m);<br />&#160; &#160; &#160; &#160; &#160; &#160; }<br />&#160; &#160; &#160; &#160; }<br />&#160; &#160; }<br />&#160; &#160; return 0;<br />}</p>]]></description>
			<author><![CDATA[dummy@example.com (batsom)]]></author>
			<pubDate>Mon, 29 Aug 2022 06:56:35 +0000</pubDate>
			<guid>https://www.gentoo-zh.org/viewtopic.php?pid=318#p318</guid>
		</item>
	</channel>
</rss>
