{"id":312934,"date":"2024-05-20T22:51:43","date_gmt":"2024-05-20T14:51:43","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/312934.html"},"modified":"2024-05-20T22:52:00","modified_gmt":"2024-05-20T14:52:00","slug":"c%e8%af%ad%e8%a8%80%e6%80%8e%e4%b9%88%e6%b1%821%e5%88%b01000%e4%b9%8b%e9%97%b4%e5%90%84%e4%bd%8d%e6%95%b0%e5%ad%97%e4%b9%8b%e5%92%8c%e4%b8%ba15%e7%9a%84%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/312934.html","title":{"rendered":"C\u8bed\u8a00\u600e\u4e48\u6c421\u52301000\u4e4b\u95f4\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e3a15\u7684\u6570"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26233717\/e9ad8e9a-c43d-4e8a-88b2-3a59a79b9a28.webp\" alt=\"C\u8bed\u8a00\u600e\u4e48\u6c421\u52301000\u4e4b\u95f4\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e3a15\u7684\u6570\" \/><\/p>\n<p><p>\u5728C\u8bed\u8a00\u4e2d\uff0c\u6c42\u89e31\u52301000\u4e4b\u95f4\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e3a15\u7684\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u3001\u6a21\u8fd0\u7b97\uff08%\uff09\u3001\u6574\u9664\u8fd0\u7b97\uff08\/\uff09\u7b49\u65b9\u6cd5\u5b9e\u73b0\u3002<strong>\u8fd9\u4e9b\u65b9\u6cd5\u7ed3\u5408\u8d77\u6765\uff0c\u53ef\u4ee5\u9ad8\u6548\u5730\u89e3\u6790\u6bcf\u4e2a\u6570\u7684\u5404\u4e2a\u4f4d\u6570\uff0c\u5e76\u8ba1\u7b97\u5b83\u4eec\u7684\u548c<\/strong>\u3002\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u904d\u5386\u65b9\u6cd5\u4ee5\u53ca\u6570\u5b57\u7684\u62c6\u89e3\u8fc7\u7a0b\uff0c\u8fd9\u662f\u89e3\u9898\u7684\u5173\u952e\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u904d\u53861\u52301000\u7684\u6570\u5b57<\/h3>\n<\/p>\n<p><p>\u904d\u5386\u662f\u89e3\u51b3\u8fd9\u7c7b\u95ee\u9898\u7684\u7b2c\u4e00\u6b65\u3002\u6211\u4eec\u9700\u8981\u4ece1\u904d\u5386\u52301000\uff0c\u9488\u5bf9\u6bcf\u4e00\u4e2a\u6570\uff0c\u8ba1\u7b97\u5176\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\uff0c\u7136\u540e\u5224\u65ad\u548c\u662f\u5426\u4e3a15\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u53ef\u4ee5\u901a\u8fc7for\u5faa\u73af\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">for(int i = 1; i &lt;= 1000; i++) {<\/p>\n<p>    \/\/ \u5728\u8fd9\u91cc\u8ba1\u7b97i\u7684\u5404\u4f4d\u4e4b\u548c<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u8ba1\u7b97\u6570\u5b57\u5404\u4f4d\u4e4b\u548c<\/h3>\n<\/p>\n<p><p>\u8ba1\u7b97\u4e00\u4e2a\u6574\u6570\u5404\u4f4d\u4e4b\u548c\u7684\u5173\u952e\u5728\u4e8e\u5982\u4f55\u62c6\u89e3\u51fa\u6bcf\u4e00\u4f4d\u3002\u8fd9\u91cc\u53ef\u4ee5\u5229\u7528<strong>\u6a21\u8fd0\u7b97\uff08%\uff09\u548c\u6574\u9664\u8fd0\u7b97\uff08\/\uff09<\/strong>\u3002\u6211\u4eec\u77e5\u9053\uff0c\u4efb\u4f55\u6570mod 10\u90fd\u4f1a\u5f97\u5230\u5176\u4e2a\u4f4d\u6570\uff0c\u800c\u6574\u966410\u5219\u4f1a\u53bb\u6389\u4e2a\u4f4d\u6570\uff0c\u8fd9\u4e3a\u6211\u4eec\u9010\u4f4d\u5904\u7406\u63d0\u4f9b\u4e86\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5bf9\u4e8e\u6570\u5b57123\uff1a<\/p>\n<\/p>\n<ul>\n<li>123 % 10 = 3\uff08\u4e2a\u4f4d\uff09<\/li>\n<li>123 \/ 10 = 12<\/li>\n<li>\u7136\u540e\u5bf912\u91cd\u590d\u4e0a\u8ff0\u64cd\u4f5c\uff0c\u76f4\u5230\u5546\u4e3a0\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u5224\u65ad\u6761\u4ef6\u548c\u8f93\u51fa\u7ed3\u679c<\/h3>\n<\/p>\n<p><p>\u6bcf\u5f53\u6211\u4eec\u8ba1\u7b97\u51fa\u4e00\u4e2a\u6570\u7684\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\uff0c\u5c31\u9700\u8981\u5224\u65ad\u8fd9\u4e2a\u548c\u662f\u5426\u7b49\u4e8e15\u3002\u5982\u679c\u7b49\u4e8e\uff0c\u5c31\u8f93\u51fa\u8fd9\u4e2a\u6570\u3002\u6574\u4e2a\u5224\u65ad\u548c\u8f93\u51fa\u7684\u8fc7\u7a0b\u53ef\u4ee5\u653e\u5728\u904d\u5386\u7684\u5faa\u73af\u4e2d\u6267\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">if(\u6570\u5b57\u4e4b\u548c == 15) {<\/p>\n<p>    printf(&quot;%d\\n&quot;, i);<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u7efc\u5408\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u5b8c\u6210\u4efb\u52a1\u7684\u5b8c\u6574C\u8bed\u8a00\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">#include &lt;stdio.h&gt;<\/p>\n<p>int m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n() {<\/p>\n<p>    for(int i = 1; i &lt;= 1000; i++) {<\/p>\n<p>        int sum = 0; \/\/ \u521d\u59cb\u5316\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e3a0<\/p>\n<p>        int num = i;  \/\/ \u7528\u4e8e\u64cd\u4f5c\u7684\u4e34\u65f6\u53d8\u91cf<\/p>\n<p>        while(num &gt; 0) {<\/p>\n<p>            sum += num % 10; \/\/ \u52a0\u4e0a\u4e2a\u4f4d\u6570\u5b57<\/p>\n<p>            num \/= 10; \/\/ \u79fb\u9664\u5df2\u52a0\u7684\u4e2a\u4f4d\u6570\u5b57<\/p>\n<p>        }<\/p>\n<p>        if(sum == 15) {<\/p>\n<p>            printf(&quot;%d\\n&quot;, i); \/\/ \u8f93\u51fa\u6ee1\u8db3\u6761\u4ef6\u7684\u6570\u5b57<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>    return 0;<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5b8c\u6574\u4f53\u73b0\u4e86\u5982\u4f55\u904d\u5386\u3001\u5982\u4f55\u62c6\u89e3\u6570\u5b57\u4ee5\u53ca\u5982\u4f55\u8f93\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u6570\u5b57\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u80fd\u6709\u6548\u627e\u51fa1\u52301000\u4e4b\u95f4\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e3a15\u7684\u6240\u6709\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6027\u80fd\u4f18\u5316<\/h3>\n<\/p>\n<p><p>\u867d\u7136\u4e0a\u8ff0\u4ee3\u7801\u5df2\u8db3\u591f\u89e3\u51b3\u95ee\u9898\uff0c\u4f46\u5728\u9762\u5bf9\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c\u6027\u80fd\u4f18\u5316\u53d8\u5f97\u5c24\u4e3a\u91cd\u8981\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u9884\u5148\u6392\u9664\u90a3\u4e9b\u660e\u663e\u4e0d\u53ef\u80fd\u8fbe\u5230\u5404\u4f4d\u548c\u4e3a15\u7684\u5927\u6570\uff0c\u6216\u8005\u4f7f\u7528\u5e76\u884c\u8ba1\u7b97\u7b49\u6280\u672f\u52a0\u901f\u5904\u7406\u8fc7\u7a0b\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u672c\u95ee\u9898\u800c\u8a00\uff0c\u7531\u4e8e\u8303\u56f4\u53ea\u9650\u4e8e1\u52301000\uff0c\u4e0a\u8ff0\u7b80\u5355\u65b9\u6cd5\u5df2\u7ecf\u76f8\u5f53\u9ad8\u6548\u4e14\u6613\u4e8e\u7406\u89e3\u3002\u5f53\u63a2\u7d22\u66f4\u590d\u6742\u6216\u6570\u636e\u89c4\u6a21\u66f4\u5927\u7684\u95ee\u9898\u65f6\uff0c\u8003\u8651\u8fdb\u4e00\u6b65\u4f18\u5316\u4f1a\u662f\u4e00\u4e2a\u597d\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u7cbe\u7ec6\u7684\u903b\u8f91\u5212\u5206\u548c\u6709\u6548\u7684\u4ee3\u7801\u5b9e\u73b0\uff0c\u6211\u4eec\u4e0d\u4ec5\u89e3\u51b3\u4e86\u7279\u5b9a\u7684\u95ee\u9898\uff0c\u8fd8\u638c\u63e1\u4e86\u5904\u7406\u7c7b\u4f3c\u95ee\u9898\u7684\u6709\u6548\u65b9\u6cd5\u3002\u8fd9\u79cd\u80fd\u529b\u5bf9\u4e8e\u4efb\u4f55\u4e00\u4f4d\u7f16\u7a0b\u4eba\u5458\u6765\u8bf4\u90fd\u662f\u6781\u5176\u5b9d\u8d35\u7684\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5728C\u8bed\u8a00\u4e2d\uff0c\u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u6570\u7684\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u662f\u5426\u4e3a15\uff1f<\/strong><br \/>\n\u5728C\u8bed\u8a00\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u548c\u53d6\u4f59\u64cd\u4f5c\u6765\u5224\u65ad\u4e00\u4e2a\u6570\u7684\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u662f\u5426\u4e3a15\u3002\u904d\u53861\u52301000\u4e4b\u95f4\u7684\u6240\u6709\u6570\uff0c\u9010\u4e2a\u8ba1\u7b97\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\uff0c\u5e76\u4e0e15\u8fdb\u884c\u6bd4\u8f83\u5373\u53ef\u3002<\/p>\n<p><strong>2. C\u8bed\u8a00\u4e2d\u5982\u4f55\u627e\u51fa1\u52301000\u4e4b\u95f4\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e3a15\u7684\u6570\uff1f<\/strong><br \/>\n\u8981\u627e\u52301\u52301000\u4e4b\u95f4\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e3a15\u7684\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u7ed3\u6784\uff0c\u5728\u6bcf\u6b21\u5faa\u73af\u4e2d\u5224\u65ad\u5f53\u524d\u6570\u7684\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u662f\u5426\u4e3a15\uff0c\u5982\u679c\u662f\u5219\u6253\u5370\u8f93\u51fa\u8be5\u6570\u3002<\/p>\n<p><strong>3. \u5982\u4f55\u4f18\u5316C\u8bed\u8a00\u4e2d\u6c421\u52301000\u4e4b\u95f4\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e3a15\u7684\u6570\u7684\u7b97\u6cd5\uff1f<\/strong><br \/>\n\u4e3a\u4e86\u4f18\u5316\u7b97\u6cd5\uff0c\u53ef\u4ee5\u5229\u7528\u4e00\u4e9b\u6570\u5b66\u7279\u6027\u6765\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\u3002\u89c2\u5bdf\u53ef\u4ee5\u53d1\u73b0\uff0c\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e3a15\u7684\u6570\u5fc5\u5b9a\u662f3\u7684\u500d\u6570\uff0c\u56e0\u4e3a3\u7684\u500d\u6570\u7684\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e5f\u662f3\u7684\u500d\u6570\u3002\u56e0\u6b64\uff0c\u5728\u5faa\u73af\u5224\u65ad\u65f6\uff0c\u53ef\u4ee5\u5148\u5224\u65ad\u5f53\u524d\u6570\u662f\u5426\u4e3a3\u7684\u500d\u6570\uff0c\u5982\u679c\u662f\u518d\u8ba1\u7b97\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u662f\u5426\u4e3a15\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u5927\u90e8\u5206\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728C\u8bed\u8a00\u4e2d\uff0c\u6c42\u89e31\u52301000\u4e4b\u95f4\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u4e3a15\u7684\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u3001\u6a21\u8fd0\u7b97\uff08%\uff09\u3001\u6574\u9664\u8fd0\u7b97\uff08\/\uff09\u7b49\u65b9\u6cd5\u5b9e\u73b0\u3002 [&hellip;]","protected":false},"author":3,"featured_media":312947,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/312934"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=312934"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/312934\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/312947"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=312934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=312934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=312934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}