{"id":138,"date":"2022-08-06T12:54:51","date_gmt":"2022-08-06T04:54:51","guid":{"rendered":"http:\/\/www.zhangxiaohei.cn\/?p=138"},"modified":"2022-08-06T12:54:51","modified_gmt":"2022-08-06T04:54:51","slug":"%e4%ba%94c%e8%af%ad%e8%a8%80%e6%95%99%e7%a8%8bfor-%e5%be%aa%e7%8e%af","status":"publish","type":"post","link":"http:\/\/www.zhangxiaohei.cn\/?p=138","title":{"rendered":"(\u4e94)C\u8bed\u8a00\u6559\u7a0b&#038;for \u5faa\u73af"},"content":{"rendered":"\n<p>\u4eca\u5929\uff0c\u6211\u4eec\u7ee7\u7eed\u6765\u5b66\u4e60C\u8bed\u8a00\u91cc\u7684for\u5faa\u73af<\/p>\n\n\n\n<p>\u7167\u5e38\uff0c\u4e0a\u8282\u8bfe\u7b54\u6848\u5728\u6700\u5e95\u4e0b\uff0c\u4e0a\u8282\u8bfe\u94fe\u63a5\uff1a<\/p>\n\n\n\n<p>(\u56db)C\u8bed\u8a00\u6559\u7a0b&amp;if \u5224\u65ad\u4e0e\u903b\u8f91\u8fd0\u7b97\u7b26<\/p>\n\n\n\n<p>\u4eca\u5929\uff0c\u6211\u4eec\u5b66\u4e60C\u8bed\u8a00\u91cc\u6bd4\u8f83\u91cd\u8981\u7684\u77e5\u8bc6\uff1afor\u5faa\u73af<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u53ef\u662fC\u8bed\u8a00\u91cc\u91cd\u8981\u7684\u77e5\u8bc6\u70b9\uff0c\u90fd\u597d\u597d\u5b66\u4e60\u54c8\uff0c\u4e0d\u61c2\u591a\u770b\u770b<\/p>\n\n\n\n<p>\u5148\u4ece\u4f8b\u5b50\u5f00\u59cb<\/p>\n\n\n\n<p>\u6bd4\u5982\uff0c\u6211\u4eec\u73b0\u5728\u8981\u63a5\u53d7\u7528\u6237\u8f93\u5165\u7684\u4e09\u4e2a\u6570\u5b57&nbsp;<\/p>\n\n\n\n<p>\u5e38\u89c4\u7684\u5199\u6cd5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<p>scanf(&#8220;%d&#8221;,&amp;a);<\/p>\n\n\n\n<p>scanf(&#8220;%d&#8221;,&amp;b);<\/p>\n\n\n\n<p>scanf(&#8220;%d&#8221;,&amp;c);<\/p>\n\n\n\n<p>\u4f46\u662f\uff0c\u5982\u679c\u6211\u4eec\u8981\u5199\u5341\u904d\u5462\uff1f\u4e00\u767e\u904d\u5462\uff1f<\/p>\n\n\n\n<p>\u80af\u5b9a\u5c31\u4e0d\u80fd\u8fd9\u4e48\u5199\u4e86\uff0c\u56e0\u6b64\uff0cfor\u5faa\u73af\u4e5f\u5c31\u51fa\u6765\u4e86<\/p>\n\n\n\n<p>for\u5faa\u73af\u57fa\u672c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>for\uff08\u5355\u6b21\u8868\u8fbe\u5f0f;\u6761\u4ef6\u8868\u8fbe\u5f0f;\u672b\u5c3e\u5faa\u73af\u4f53\uff09<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>&nbsp; &nbsp; \u4e2d\u95f4\u5faa\u73af\u4f53\uff1b<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\uff0c\u54b1\u4eec\u6765\u8be6\u7ec6\u7684\u8bb2\u4e00\u8bb2<\/p>\n\n\n\n<p>for\u5faa\u73af\u65f6\uff0c\u4f60\u9700\u8981\u6709\u4e00\u4e2a\u53d8\u91cf\u5e76\u8d4b\u503c\uff0c\u968f\u7740\u5faa\u73af\u6b21\u6570\u7684\u589e\u591a\u800c\u589e\u5927\uff0c\u4e00\u65e6\u8fd9\u4e2a\u53d8\u91cf\u5230\u8fbe\u4e86\u9876\uff0c\u5c31\u4e0d\u80fd\u5faa\u73af\u4e86\uff0c\u5c31\u81ea\u52a8\u9000\u51fa\u4e86<\/p>\n\n\n\n<p>\u8fd9\u5c31\u662ffor\u7684\u57fa\u672c\u539f\u7406<\/p>\n\n\n\n<p>\u90a3\u4e48\u53d8\u91cf\u5462\uff1f\u6211\u4eec\u90fd\u4f1a\u5199\u4e0a int i ,\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5199int a\uff0c\u4f46\u662f\u4e00\u822c\u5faa\u73af\u7528i\uff0cj\uff0ck<\/p>\n\n\n\n<p>\u8d4b\u503c\u5462\uff1fi=0 \uff0c\u8fd9\u91cc&nbsp;i=\u5565\u90fd\u884c<\/p>\n\n\n\n<p>\u6240\u4ee5\u5355\u6b21\u8868\u8fbe\u5f0f\u91cc\u5199 i=0\u5c31OK\uff0cint i \u5199\u5728\u524d\u9762<\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5199\u5728\u4e00\u8d77\uff0c\u5199\u6210 int i=0 ;<\/p>\n\n\n\n<p>\u6761\u4ef6\u8868\u8fbe\u5f0f\u5c31\u662f\u6bcf\u6b21 i \u7684\u589e\u52a0\u6570\u91cf<\/p>\n\n\n\n<p>\u6bd4\u5982 i = i+1\uff0c\u5c31\u662f\u6bcf\u6b21 i \u5faa\u73af\u4e00\u6b21\u540e\u52a0 1<\/p>\n\n\n\n<p>\u540c\u6837\uff0ci = i+2 \u5c31\u662f\u52a0 2<\/p>\n\n\n\n<p>\u4f46\u662f\u4e00\u822c\u6211\u4eec\u4e0d\u8fd9\u6837\u5199\uff0c\u592a\u7e41\u7410\u4e86\uff0c\u4e00\u822c\u6211\u4eec\u5199\u6210 i++\uff0c\u8fd9\u662f\u4ee3\u8868 i +1<\/p>\n\n\n\n<p>\u90a3\u4e48 i+2 \u5462\uff1f\u662f i+=2\uff0c\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u628a i++\u5199\u6210i+=1<\/p>\n\n\n\n<p>\u8fd8\u6709\u4e2a\u672b\u5c3e\u5faa\u73af\u4f53\uff0c\u8fd9\u5c31\u662f\u90a3\u4e2a\u6761\u4ef6\uff0c\u6761\u4ef6\u4e00\u6ee1\u8db3\uff0c\u5faa\u73af\u5c31\u9000\u51fa<\/p>\n\n\n\n<p>\u6bd4\u5982\u5f53 i &gt;10\u65f6\uff0c\u5faa\u73af\u9000\u51fa\uff0c\u6216\u8005i &gt;5\u4e5f\u53ef\u4ee5\uff0c\u5f53\u7136&gt;=\u4e5f\u53ef\u4ee5<\/p>\n\n\n\n<p>\u4e2d\u95f4\u5faa\u73af\u4f53\u5c31\u662f\u5faa\u73af\u65f6\u8981\u6267\u884c\u7684\u8bed\u53e5<\/p>\n\n\n\n<p>\u6240\u4ee5for\u5faa\u73af\u7684\u8bed\u53e5\u5c31\u90fd\u51fa\u6765\u4e86\uff0c\u8ba9\u6211\u4eec\u8bd5\u7740\u5199\u70b9\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<p>\u63a5\u53d7\u7528\u6237\u8f93\u5165\u7684\u4e09\u4e2a\u6570\u5b57\uff0c\u7136\u540e\u8f93\u51fa\u5b83\u4eec\u7684\u548c<\/p>\n\n\n\n<p>\u5c31\u53ef\u4ee5\u5199\u6210\uff1a<\/p>\n\n\n\n<p>for(int i=0;i&lt;3;i++)&nbsp; &nbsp; &nbsp; &nbsp;\/\/\u6ce8\u610f\u8fd9\u662f\u5206\u53f7<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>&nbsp; &nbsp; scanf(&#8220;%d&#8221;,&amp;a);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u5b83\u7684\u6267\u884c\u8fc7\u7a0b\u5c31\u662f\uff1ai \u4e3a0\uff0c\u5148\u5224\u65adi\u662f\u4e0d\u662f\u5c0f\u4e8e3\uff0c\u7136\u540e\u6267\u884c\u8ba9\u7528\u6237\u8f93\u5165\u7684\u64cd\u4f5c\uff0c\u7136\u540ei++<\/p>\n\n\n\n<p>i \u4e3a1\uff0c\u518d\u5224\u65ad\u4e00\u4e0b\uff0c\u7136\u540e\u518d\u6267\u884c\u8ba9\u7528\u6237\u8f93\u5165\u7684\u64cd\u4f5c\uff0c\u7136\u540ei++<\/p>\n\n\n\n<p>i \u4e3a2\uff0c\u540c\u6837\u518d\u5224\u65ad\uff0c\u7136\u540e\u8ba9\u7528\u6237\u8f93\u5165\uff0c\u7136\u540ei++<\/p>\n\n\n\n<p>i \u4e3a3\uff0c\u5224\u65ad i \u4e0d\u5c0f\u4e8e3\uff0c\u6240\u4ee5\u76f4\u63a5\u9000\u51fa\uff0c\u5faa\u73af\u4f53\u4e00\u5171\u6267\u884c3\u6b21<\/p>\n\n\n\n<p>\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u5199\u6210 i=1;i&lt;=3;i++\u8fd9\u6837\u7684\u5f62\u5f0f\uff0c\u6216\u8005 i=1;i&lt;4;i++\uff0c\u90fd\u53ef\u4ee5<\/p>\n\n\n\n<p>\u4f46\u662f\u4e00\u5b9a\u8981\u505a\u5230\u7b80\u5355\u660e\u4e86\uff0c\u8ba9\u81ea\u5df1\u770b\u5f97\u61c2<\/p>\n\n\n\n<p>\u9664\u4e86for\u5faa\u73af\uff0c\u5176\u5b9e\u8fd8\u6709\u522b\u7684\u5faa\u73af\u65b9\u5f0f\uff0c\u8fd8\u6709while\u5faa\u73af\u548cdo-while\u5faa\u73af\uff0c\u4e0b\u9762\u5206\u522b\u4ecb\u7ecd\u4e00\u4e0b<\/p>\n\n\n\n<p>while(\u6761\u4ef6\u8868\u8fbe\u5f0f)<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>&nbsp; &nbsp; \u6267\u884c\u8bed\u53e5;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>do{<\/p>\n\n\n\n<p>&nbsp; &nbsp; \u6267\u884c\u8bed\u53e5;<\/p>\n\n\n\n<p>}while(\u6761\u4ef6\u8868\u8fbe\u5f0f)<\/p>\n\n\n\n<p>\u90a3\u4e48\u4e24\u8005\u7684\u533a\u522b\u5462\uff1f<\/p>\n\n\n\n<p>while\u662f\u5148\u5224\u65ad\u540e\u6267\u884c\uff0cdo-while\u662f\u5148\u6267\u884c\u540e\u5224\u65ad\uff0cwhile\u53ef\u80fd\u4e0d\u4f1a\u6267\u884c\uff0c\u4f46do-while\u4e00\u5b9a\u4f1a\u6267\u884c\u4e00\u6b21<\/p>\n\n\n\n<p>\u5176\u5b9e\u672c\u8d28\u4e0a\u6ca1\u5565\u533a\u522b\uff0c\u53ea\u662fdo-while\u4e0d\u592a\u4e00\u6837\uff0cfor\u548cwhile\u53ef\u4ee5\u4e92\u76f8\u8f6c\u6362<\/p>\n\n\n\n<p>\u81ea\u5df1\u7528\u7740\u54ea\u4e2a\u597d\u4f7f\u5c31\u7528\u54ea\u4e2a\u5c31\u884c\u4e86\uff0c\u4f46\u662f\u5fc5\u987b\u90fd\u5f97\u4e86\u89e3<\/p>\n\n\n\n<p>\u7ed9\u4e2a\u4f8b\u5b50\uff1a\uff08\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff09<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">include<\/h1>\n\n\n\n<p>int main(){<\/p>\n\n\n\n<p>&nbsp; &nbsp; for (int i = 1; i &lt;= 9; i++){<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int j = i; j &lt;= 9; j++){<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;%d*%d=%-3d&#8221;, i, j, i * j);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&#8220;\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; return 0;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u81ea\u5df1\u597d\u597d\u7422\u78e8\u7422\u78e8\uff0c\u5176\u5b9e\u4e0d\u96be<\/p>\n\n\n\n<p>\u4e5d\u4e5d\u4e58\u6cd5\u8868<br>\u5bf9\u4e86\uff0c\u8fd8\u6ca1\u544a\u8bc9\u4f60\u4eec%-3d\u7684\u610f\u601d\u5462\uff0c-\u4ee3\u8868\u5de6\u5bf9\u9f50\uff0c3\u662f\u5360\u4e09\u4e2a\u4f4d\u7f6e\uff0c\u4e0d\u591f\u7528\u7a7a\u683c\u8865\u9f50\uff0c\u8fd9\u6837\u53ef\u4ee5\u66f4\u597d\u7684\u683c\u5f0f\u5316\u8f93\u51fa\uff0c\u4fbf\u4e8e\u4eba\u4eec\u9605\u8bfb<\/p>\n\n\n\n<p>\u5982\u679c\u4e0d\u5e26\u5462\uff1f<\/p>\n\n\n\n<p>\u4e0d\u5e26-%3d\uff0c\u53ef\u4ee5\u770b\u51fa\u4e71\u4e86\u597d\u591a<br>\u662f\u4e0d\u662f\u4e71\u4e86\uff1f\u5e26\u4e0a\u8fd8\u662f\u5f88\u597d\u770b\u7684<\/p>\n\n\n\n<p>\u4e0b\u9762\u5f00\u59cb\u603b\u7ed3\uff1a<\/p>\n\n\n\n<p>\u5176\u5b9e\u6ca1\u5565\u603b\u7ed3\u7684\uff0c\u81ea\u5df1\u5728\u8111\u5b50\u91cc\u8fc7\u4e00\u904dfor\uff0cwhile\u548cdo-while\u7684\u53e5\u5f0f\uff0c\u4f5c\u8005\u8fd8\u8d34\u5fc3\u7684\u4e3a\u4f60\u4eec\u51c6\u5907\u4e86\u8bfe\u540e\u7ec3\u4e60\u9898\uff0c\u80fd\u505a\u4e86\u5c31\u4ee3\u8868\u4f60\u4f1a\u8fd9\u8282\u7684\u77e5\u8bc6\u4e86<\/p>\n\n\n\n<p>\u4e0a\u9898\u7b54\u6848\uff1a<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">include<\/h1>\n\n\n\n<p>int main(){<\/p>\n\n\n\n<p>&nbsp; &nbsp; int age, score;<\/p>\n\n\n\n<p>&nbsp; &nbsp; printf(&#8220;\u8bf7\u8f93\u5165\u60a8\u7684\u5e74\u9f84\u548c\u5206\u6570\uff1a&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; scanf(&#8220;%d%d&#8221;, &amp;age, &amp;score);<\/p>\n\n\n\n<p>&nbsp; &nbsp; if (age &gt; 18){<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if (score &gt; 60){<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;\u4f60\u53ef\u4ee5\u4f7f\u7528\u8be5\u8f6f\u4ef6\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; else{<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;\u4f60\u7684\u5206\u6570\u592a\u4f4e\u4e86\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; else if (age &lt; 18 &amp;&amp; score &gt; 60){<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;\u4f60\u592a\u5c0f\u4e86\uff0c\u4e0d\u80fd\u4f7f\u7528\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; else{<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;\u8f93\u5165\u6709\u8bef\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; return 0;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u4f5c\u8005\u4eb2\u6d4b\u65e0\u8bef<\/p>\n\n\n\n<p>\u4eca\u5929\u7684\u9898\u5728\u8fd9\u91cc\uff1a<\/p>\n\n\n\n<p>\u8981\u6c42\u7528\u6237\u8f93\u5165\u4e00\u4e2a\u6570\u5b57\uff0c\u5224\u65ad\u662f\u5426\u4e3a\u8d28\u6570\uff0c\u5982\u679c\u662f\uff0c\u5219\u8f93\u51fa&#8221;\u8fd9\u4e2a\u6570\u662f\u8d28\u6570&#8221;\uff0c\u5982\u679c\u4e0d\u662f\uff0c\u5219\u8f93\u51fa&#8221;\u8fd9\u4e2a\u6570\u4e0d\u662f\u8d28\u6570&#8221; \u4f5c\u8005\uff1a\u6c5f\u6653\u9526\u7fc1 https:\/\/www.bilibili.com\/read\/cv7164268?spm_id_from=333.999.0.0 \u51fa\u5904\uff1abilibili<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\uff0c\u6211\u4eec\u7ee7\u7eed\u6765\u5b66\u4e60C\u8bed\u8a00\u91cc\u7684for\u5faa\u73af \u7167\u5e38\uff0c\u4e0a\u8282\u8bfe\u7b54\u6848\u5728\u6700\u5e95\u4e0b\uff0c\u4e0a\u8282\u8bfe\u94fe\u63a5\uff1a (\u56db)C\u8bed\u8a00\u6559\u7a0b&amp;i<\/p><\/div>\n<div class=\"blog-btn\"><a href=\"http:\/\/www.zhangxiaohei.cn\/?p=138\" class=\"home-blog-btn\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-138","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":0,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}