{"id":442,"date":"2015-06-14T19:54:17","date_gmt":"2015-06-14T11:54:17","guid":{"rendered":"http:\/\/yangwang.hk\/?p=442"},"modified":"2015-06-14T19:54:17","modified_gmt":"2015-06-14T11:54:17","slug":"3-2%e3%80%81if%e7%9a%84%e5%af%b9%e9%9d%a2-else","status":"publish","type":"post","link":"https:\/\/yangwang.hk\/?p=442","title":{"rendered":"3.2\u3001if\u7684\u5bf9\u9762 \u2014\u2014 else"},"content":{"rendered":"<p>\u4e0a\u9762\u6211\u4eec\u5b66\u4e60\u4e86if\u8bed\u53e5\uff0c\u6211\u4eec\u5df2\u7ecf\u53ef\u4ee5\u5b9e\u73b0\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u53bb\u63a7\u5236\u7a0b\u5e8f\u8fd0\u884c\u7684\u65b9\u5411\u7684\u529f\u80fd\u4e86\u3002\u4f46\u662f\u4f3c\u4e4e\u53ea\u6709\u4e00\u4e2aif\u6709\u70b9\u4e0d\u592a\u591f\u7528\uff0c\u6bd5\u7adf\u4eba\u7c7b\u7684\u8bed\u8a00\u4e2d\u662f<\/p>\n<p>\u5982\u679cxxx\uff0c\u90a3\u4e48yyy\uff0c\u5426\u5219zzz<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728if\u6240\u5224\u65ad\u7684\u60c5\u51b5\u4e4b\u4e0b\uff0c\u8fd8\u6709\u53e6\u4e00\u79cd\u4e0e\u4e4b\u5bf9\u5e94\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u4f8b\u5982\u6211\u4eec\u5728\u68c0\u67e5\u7528\u6237\u7684\u8f93\u5165\u6570\u636e\u65f6\uff0c\u53d1\u73b0\u5408\u6cd5\u7684\u8f93\u5165\u9700\u8981\u7ed9\u51fa\u63d0\u793a\uff0c\u975e\u6cd5\u7684\u8f93\u5165\u66f4\u8981\u7ed9\u51fa\u63d0\u793a\uff0c\u53ea\u6709\u4e00\u4e2aif\uff0c\u5b9e\u73b0\u8d77\u6765\u5c31\u4f1a\u6bd4\u8f83\u9ebb\u70e6\u3002\u597d\u5728c\u8bed\u8a00\u8fd8\u63d0\u4f9b\u4e86\u53e6\u4e00\u4e2a\u5173\u952e\u5b57\uff1a<\/p>\n<p>else<\/p>\n<p>\u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u8ba9\u6211\u4eec\u4ece\u4e00\u4e2a\u4f8b\u5b50\u5f00\u59cb\u3002<\/p>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u5b66\u4f1a\u5236\u4f5c\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u4e8c\u6b21\u65b9\u7a0b\u7684\u6839\u7684\u8ba1\u7b97\u5668\uff0c\u8f93\u5165a\uff0cb\uff0cc\u5c31\u53ef\u4ee5\u5f97\u5230\u7ed3\u679c\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u4e0d\u80fd\u4ec0\u4e48\u90fd\u7531\u6211\u6765\u5199\uff0c\u8bf7\u4f60\u6839\u636e\u524d\u9762\u6240\u5b66\u4e60\u7684\u77e5\u8bc6\uff0c\u5c06\u6700\u57fa\u672c\u7684\u90e8\u5206\u7684\u4ee3\u7801\u81ea\u5df1\u5199\u51fa\u6765\u3002<\/p>\n<p>\u6211\u4eec\u9700\u8981\u8f93\u5165a\uff0cb\uff0cc\u4e09\u4e2a\u6570\u7684\u503c\uff0c\u8fd8\u9700\u8981\u4e24\u4e2a\u53d8\u91cfx1\uff0cx2\u53bb\u4fdd\u5b58\u6839\u7684\u503c\uff0c\u56e0\u6b64\u6211\u4eec\u81f3\u5c11\u9700\u8981\u5b9a\u4e495\u4e2a\u53d8\u91cf\u3002\u63a5\u7740\uff0c\u56e0\u4e3aabc\u4e0d\u4e00\u5b9a\u662f\u6574\u6570\uff0cx1\u548cx2\u540c\u6837\uff0c\u56e0\u6b64\u6211\u4eec\u8fd9\u91cc\u5e94\u8be5\u9009\u7528\u6d6e\u70b9\u578b\u53d8\u91cf\uff0c\u8bf7\u4f7f\u7528double<\/p>\n<p><span style=\"color: #ff0000;\">\u8fd9\u91ccps\u4e00\u70b9\uff1a<span style=\"color: #000000;\">\u4eca\u540e\u6211\u4eec\u9700\u8981\u4f7f\u7528\u6d6e\u70b9\u578b\u53d8\u91cf\u65f6\uff0c\u5982\u679cfloat\u548cdouble\u90fd\u53ef\u4ee5\u6ee1\u8db3\u8981\u6c42\uff0c<\/span>\u90a3\u4e48\u8bf7\u5c3d\u91cf\u9009\u62e9double<span style=\"color: #000000;\">\uff0cdouble\u7684\u786e\u4f1a\u5360\u7528\u6bd4float\u5927\u4e00\u500d\u7684\u5185\u5b58\uff0c\u4f46\u662f\u4ee5\u73b0\u5728\u8ba1\u7b97\u673a\u7684\u6027\u80fd\u6765\u8bf4\uff0c\u591a\u51e0\u5b57\u8282\u6839\u672c\u770b\u4e0d\u51fa\u533a\u522b\u3002\u53e6\u5916\u7f51\u4e0a\u5f88\u591a\u4eba\u8bf4<\/span>double\u4f1a\u6bd4float\u6162\u5f97\u591a<span style=\"color: #000000;\">\uff0c<\/span>\u8fd9\u662f\u4e0d\u8d1f\u8d23\u4efb\u7684\u8bf4\u6cd5\uff01\u73b0\u5728\u7684CPU\u90fd\u4f1a\u96c6\u6210fpu\u53bb\u5904\u7406\u6d6e\u70b9\u8fd0\u7b97\uff0c\u5728\u5f88\u591a\u60c5\u51b5\u4e0bfloat\u90fd\u662f\u6362\u6210double\u53bb\u8fd0\u7b97\u7684\uff01\u56e0\u6b64double\u6709\u53ef\u80fd\u548cfloat\u4e00\u6837\u5feb\uff0c\u751a\u81f3\u662f\u6bd4float\u66f4\u5feb<\/span><\/p>\n<p>\u611f\u5174\u8da3\u7684\u53c2\u89c1\uff1a<a href=\"http:\/\/stackoverflow.com\/questions\/417568\/float-vs-double-performance\">http:\/\/stackoverflow.com\/questions\/417568\/float-vs-double-performance<\/a><\/p>\n<p>\u597d\u4e86\uff0c\u5feb\u5f00\u59cb\u5199\u5427\uff01\u4f60\u9700\u8981\u5148\u5b9a\u4e49\u53d8\u91cf\uff0c\u7136\u540e\u544a\u8bc9\u7528\u6237\u53bb\u8f93\u5165\u4ed6\u4eec\uff01<\/p>\n<p>\u5728\u5199\u5b8c\u4e4b\u524d\u8bf7\u4e0d\u8981\u5077\u770b\u7b54\u6848\u54e6\uff01<\/p>\n<p>\u5199\u51fa\u6765\u5e94\u8be5\u662f\u4e0b\u9762\u8fd9\u4e2a\u6837\u5b50\uff08\u7b54\u6848\u4e0d\u552f\u4e00\uff09\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n\r\nint main()\r\n{\r\n    double a, b, c, x1, x2;     \/\/abc\u4e3a\u65b9\u7a0b\u7684abc\uff0cx1\u548cx2\u7528\u4e8e\u4fdd\u5b58\u65b9\u7a0b\u7684\u6839\r\n\r\n    \/\/\u5148\u8f93\u5165\u6570\u636e\r\n    printf(&quot;\u8bf7\u8f93\u5165a:&quot;);\r\n    scanf(&quot;%lf&quot;, &amp;a);\r\n    printf(&quot;\u8bf7\u8f93\u5165b:&quot;);\r\n    scanf(&quot;%lf&quot;, &amp;b);\r\n    printf(&quot;\u8bf7\u8f93\u5165c:&quot;);\r\n    scanf(&quot;%lf&quot;, &amp;c);\r\n\r\n    printf(&quot;\u6b63\u5728\u8ba1\u7b97\u65b9\u7a0b%fx^2 + %fx + %f = 0 \u7684\u6839\uff01\\n&quot;, a, b, c);\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u8fd0\u884c\u6548\u679c<\/p>\n<div id=\"attachment_443\" style=\"width: 507px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/05\/2015-05-31-17-35-39.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-443\" class=\"size-full wp-image-443\" src=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/05\/2015-05-31-17-35-39.png\" alt=\"\u8fd0\u884c\u6548\u679c\" width=\"497\" height=\"128\" srcset=\"https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/05\/2015-05-31-17-35-39.png 497w, https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/05\/2015-05-31-17-35-39-300x77.png 300w\" sizes=\"auto, (max-width: 497px) 100vw, 497px\" \/><\/a><p id=\"caption-attachment-443\" class=\"wp-caption-text\">\u8fd0\u884c\u6548\u679c<\/p><\/div>\n<p>\u80fd\u591f\u7528\uff0c\u4e0d\u8fc7\u4f3c\u4e4e\u65b9\u7a0b\u663e\u793a\u7684\u7ed3\u679c\u770b\u8d77\u6765\u7279\u522b\u5947\u602a\uff0c\u56e0\u4e3aprintf\u9ed8\u8ba4\u76846\u4f4d\u5bf9\u4e8e\u6211\u4eec\u73b0\u5728\u6765\u8bf4\u4f3c\u4e4e\u6709\u70b9\u592a\u9ad8\u4e86\uff0c\u6211\u4eec\u53ef\u4ee5\u8ba9printf\u81ea\u52a8\u5224\u65ad\uff0c\u4e8e\u662f\u5c06\u7b2c16\u884c\u6539\u6210\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n    printf(&quot;\u6b63\u5728\u8ba1\u7b97\u65b9\u7a0b%gx^2 + %gx + %g = 0 \u7684\u6839\uff01\\n&quot;, a, b, c);\r\n<\/pre>\n<div id=\"attachment_444\" style=\"width: 486px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/05\/2015-05-31-17-44-43.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-444\" class=\"size-full wp-image-444\" src=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/05\/2015-05-31-17-44-43.png\" alt=\"\u4fee\u6539\u540e\u6548\u679c\" width=\"476\" height=\"135\" srcset=\"https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/05\/2015-05-31-17-44-43.png 476w, https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/05\/2015-05-31-17-44-43-300x85.png 300w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/a><p id=\"caption-attachment-444\" class=\"wp-caption-text\">\u4fee\u6539\u540e\u6548\u679c<\/p><\/div>\n<p>\u8fd9\u6837\u770b\u8d77\u6765\u5c31\u6b63\u5e38\u591a\u4e86\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u6765\u5b8c\u6210\u8ba1\u7b97\u65b9\u7a0b\u7684\u6839\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u5728\u521d\u4e2d\uff0c\u6211\u4eec\u5c31\u5b66\u5230\uff0c\u4e00\u5143\u4e8c\u6b21\u65b9\u7a0b\u7684\u6c42\u6839\u516c\u5f0f\u662f<\/p>\n<div id=\"attachment_446\" style=\"width: 143px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/8d5494eef01f3a2985c20d109825bc315d607ce2.jpg.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-446\" class=\"size-full wp-image-446\" src=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/8d5494eef01f3a2985c20d109825bc315d607ce2.jpg.png\" alt=\"\u6c42\u6839\u516c\u5f0f\" width=\"133\" height=\"39\" \/><\/a><p id=\"caption-attachment-446\" class=\"wp-caption-text\">\u6c42\u6839\u516c\u5f0f<\/p><\/div>\n<p>\u6211\u4eec\u5c06\u8f93\u5165\u7684abc\u5e26\u5165\u8fd9\u4e2a\u516c\u5f0f\u5c31\u53ef\u4ee5\u89e3\u51fa\u65b9\u7a0b\u7684\u6839\u4e86\uff0c\u6839\u636e\u524d\u9762\u6240\u5b66\u7684\uff0c\u6211\u4eec\u77e5\u9053sqrt\u7684\u8ba1\u7b97\u5e73\u65b9\u6839\u7684\u7a0b\u5e8f\uff0c\u90a3\u4e48\u5c31\u6709<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nx1=(-b+sqrt(b*b-4*a*c))\/(2*a);\r\nx2=(-b-sqrt(b*b-4*a*c))\/(2*a);\r\n<\/pre>\n<p>\u6709\u4eba\u4f3c\u4e4e\u60f3\u77e5\u9053\u5e73\u65b9\u662f\u600e\u4e48\u7b97\u7684\uff0cc\u8bed\u8a00\u5e76\u6ca1\u6709\u63d0\u4f9b\u76f4\u63a5\u6c42\u5e73\u65b9\u7684\u8fd0\u7b97\u7b26\uff0c\u4f46\u662f\u6211\u4eec\u8ba9\u8fd9\u4e2a\u6570\u81ea\u5df1\u4e58\u81ea\u5df1\u4e0d\u5c31\u597d\u4e86\u561b\uff01<\/p>\n<p>\u52a0\u4e0a\u663e\u793a\u7ed3\u679c\u7684\u4ee3\u7801\uff0c\u6574\u4e2a\u7a0b\u5e8f\u5e94\u8be5\u662f\u8fd9\u6837<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n\r\nint main()\r\n{\r\n    double a, b, c, x1, x2;     \/\/abc\u4e3a\u65b9\u7a0b\u7684abc\uff0cx1\u548cx2\u7528\u4e8e\u4fdd\u5b58\u65b9\u7a0b\u7684\u6839\r\n\r\n    \/\/\u5148\u8f93\u5165\u6570\u636e\r\n    printf(&quot;\u8bf7\u8f93\u5165a:&quot;);\r\n    scanf(&quot;%lf&quot;, &amp;a);\r\n    printf(&quot;\u8bf7\u8f93\u5165b:&quot;);\r\n    scanf(&quot;%lf&quot;, &amp;b);\r\n    printf(&quot;\u8bf7\u8f93\u5165c:&quot;);\r\n    scanf(&quot;%lf&quot;, &amp;c);\r\n\r\n    printf(&quot;\u6b63\u5728\u8ba1\u7b97\u65b9\u7a0b%gx^2 + %gx + %g = 0 \u7684\u6839\uff01\\n&quot;, a, b, c);\r\n\r\n    \/\/\u8ba1\u7b97\u65b9\u7a0b\u7684\u89e3\r\n    x1=(-b+sqrt(b*b-4*a*c))\/(2*a);\r\n    x2=(-b-sqrt(b*b-4*a*c))\/(2*a);\r\n\r\n    printf(&quot;x1=%g\\tx2=%g\\n&quot;, x1, x2);\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u6211\u4eec\u6765\u7f16\u8bd1\u4e00\u4e0b<\/p>\n<p>\u54a6\uff0c\u4f3c\u4e4e\u8fd9\u4e00\u6b21\u548c\u5e73\u65f6\u6709\u70b9\u4e0d\u540c\uff0c\u7f16\u8bd1\u4fe1\u606f\u5185\u51fa\u73b0\u4e86\u4e24\u4e2a\u8b66\u544a<\/p>\n<p><a href=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/123.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-448\" src=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/123.png\" alt=\"\u663e\u793a\u4e86\u8b66\u544a\" width=\"863\" height=\"116\" srcset=\"https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/123.png 863w, https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/123-300x40.png 300w, https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/123-660x88.png 660w\" sizes=\"auto, (max-width: 863px) 100vw, 863px\" \/><\/a><\/p>\n<p>\u501f\u6b64\u673a\u4f1a\uff0c\u6211\u4eec\u6b63\u597d\u6765\u5b66\u4e60\u4e00\u4e0b\u5982\u4f55\u4ece\u7f16\u8bd1\u4fe1\u606f\u4e2d\u627e\u51fa\u6211\u4eec\u7a0b\u5e8f\u7684\u95ee\u9898<\/p>\n<p>\u7b2c\u4e00\u884c\u5c31\u662f\u4e2a\u6807\u9898\uff0c\u7b2c\u4e8c\u884c\u5219\u544a\u8bc9\u4f60\uff0c\u4e0b\u9762\u51fa\u73b0\u7684\u4fe1\u606f\u90fd\u662f\u5728main\u8fd9\u4e2a\u51fd\u6570\u4e2d\u53d1\u73b0\u7684<\/p>\n<p>\u7b2c\u4e09\u884c\u524d\u9762\u544a\u8bc9\u6211\u4eec\u8fd9\u4e2a\u8b66\u544a\u5728\u7b2c19\u884c\u7684\u90a3\u4e00\u4e32\u82f1\u6587\u7684\u610f\u601d\u662f\uff1a\u8b66\u544a\uff1a\u9690\u5f0f\u51fd\u6570\u58f0\u660e \u2018sqrt&#8217; [&#8230;.]<\/p>\n<p>\u7b2c\u56db\u884c\u4e5f\u662f\u53d1\u751f\u572819\u884c\uff0c\u610f\u601d\u662f\uff1a\u8b66\u544a\uff1a\u4e0d\u517c\u5bb9\u7684\u5185\u5efa\u51fd\u6570\u9690\u5f0f\u58f0\u660e[\u9ed8\u8ba4\u5f00\u542f]<\/p>\n<p>\u8b66\u544a\u91cc\u9762\u63d0\u793a\u6211\u4eec\uff0c\u8fd9\u4e2a\u9519\u8bef\u548csqrt\u51fd\u6570\u6709\u5173\uff0c\u8fd9\u4e2a\u8b66\u544a\u662f\u5982\u4f55\u53d1\u751f\u7684\u5462\uff1f\u8ba9\u6211\u4eec\u60f3\u4e00\u60f3sqrt\u662f\u4ec0\u4e48\u51fd\u6570\uff1f\u6570\u5b66\u51fd\u6570\u561b\uff01<\/p>\n<p>\u518d\u770b\u770b\u4ee3\u7801\uff0c\u6211\u4eec\u4f3c\u4e4e\u5fd8\u4e86\u5e72\u4e00\u4ef6\u4e8b\u60c5\uff0c\u90a3\u5c31\u662f#include &lt;math.h&gt;!<\/p>\n<p>\u6211\u4eec\u5c06\u5b83\u52a0\u5230\u7a0b\u5e8f\u7684\u5f00\u5934\u518d\u7f16\u8bd1\u4e00\u6b21<\/p>\n<p><a href=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/1231.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-452\" src=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/1231.png\" alt=\"123\" width=\"564\" height=\"168\" srcset=\"https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/1231.png 564w, https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/1231-300x89.png 300w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><\/a><\/p>\n<p>\u554a\u54c8\uff0c\u8fd9\u6837\u5c31\u6ca1\u6709\u8b66\u544a\u4e86\uff01\u8fd9\u4e2a\u8b66\u544a\u53d1\u751f\u7684\u539f\u56e0\u5c31\u662f\u56e0\u4e3a\u6211\u4eec\u4f7f\u7528\u4e86\u6570\u5b66\u51fd\u6570\u5e93\u5185\u7684\u51fd\u6570\u53c8\u6ca1\u6709include\u5b83\uff0c\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u4f1a\u8fd9\u6837\u663e\u793a\uff0c\u6211\u4eec\u4ee5\u540e\u518d\u8bf4\u3002<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u6765\u8fd0\u884c\u5b83\uff0c\u89e3\u4e00\u4e2a\u65b9\u7a0bx^2 -2x\u00a0 +1 = 0\uff0c\u8fd9\u4e2a\u4e00\u5143\u4e8c\u6b21\u65b9\u7a0b\u7684\u89e3\u663e\u7136\u662fx=1\uff0c\u800c\u4e14\u53ea\u6709\u8fd9\u4e00\u4e2a\u89e3<\/p>\n<p><a href=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/1234.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-453\" src=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/1234.png\" alt=\"1234\" width=\"316\" height=\"94\" srcset=\"https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/1234.png 316w, https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/1234-300x89.png 300w\" sizes=\"auto, (max-width: 316px) 100vw, 316px\" \/><\/a><\/p>\n<p>\u7ed3\u679c\u5f88\u6b63\u786e\uff0c\u8ba9\u6211\u4eec\u6362\u4e00\u4e2a\u65b9\u7a0b\u8bd5\u4e00\u4e0b\uff0cx^2 + x + 1 = 0,\u8fd9\u4e2a\u65b9\u7a0b\u662f\u65e0\u89e3\u7684<\/p>\n<p><a href=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/12345.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-454\" src=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/06\/12345.png\" alt=\"12345\" width=\"284\" height=\"94\" \/><\/a><\/p>\n<p>nan\uff1f\u8fd9\u53c8\u662f\u4ec0\u4e48\u9b3c\uff01nan\u5176\u5b9e\u662fNot a Number\u7684\u7f29\u5199\uff0c\u610f\u601d\u662f\u8fd9\u4e0d\u662f\u4e00\u4e2a\u6570\u5b57\uff01<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4f1a\u53d1\u751f\u8fd9\u4e2a\u60c5\u51b5\u5462\uff1f\u521d\u4e2d\u7684\u6570\u5b66\u5c31\u6709\uff0c\u5f53\u4e00\u5143\u4e8c\u6b21\u65b9\u7a0b\u65e0\u89e3\u65f6\uff0c\u0394\u4f1a&lt;0\uff0c\u8fd9\u6837\u4e00\u6765\uff0c\u6839\u53f7\u4e0b\u5c31\u4f1a\u51fa\u73b0\u4e00\u4e2a\u8d1f\u6570<\/p>\n<p>\u8d1f\u6570\u8fdb\u884c\u5f00\u6839\u53f7\u8fd0\u7b97\u662f\u6ca1\u6709\u610f\u4e49\u7684\uff08\u5b9e\u6570\u8303\u56f4\u5185\uff09\uff0csqrt\u5982\u679c\u9047\u5230\u4f60\u8ba9\u4ed6\u8ba1\u7b97\u4e00\u4e2a\u8d1f\u6570\u7684\u7b97\u6570\u5e73\u65b9\u6839\u65f6\uff0c\u5c31\u4f1a\u8fd4\u56de\u4e00\u4e2anan<\/p>\n<p>\u8fd9\u6837\u5f53\u7136\u4e0d\u884c\uff0c\u5728\u65b9\u7a0b\u6ca1\u6709\u89e3\u7684\u65f6\u5019\uff0c\u6211\u4eec\u5e94\u8be5\u63d0\u9192\u7528\u6237\uff0c\u800c\u4e0d\u662f\u6254\u4e00\u5806\u9519\u8bef\u8ba9\u7528\u6237\u53bb\u731c\u6d4b\u3002\u51b5\u4e14\u6211\u4eec\u5e94\u8be5\u68c0\u67e5\u6570\u636e\u7684\u6709\u6548\u6027\u518d\u8fdb\u884c\u5904\u7406\uff08\u6bd4\u5982\u5f00\u5e73\u65b9\u8fd0\u7b97\uff09\uff0c\u8fd9\u6837\u4f1a\u6bd4\u8f83\u5b89\u5168\u3002\uff08sqrt\u8fd4\u56denan\u663e\u7136\u662f\u56e0\u4e3asqrt\u5728\u8ba1\u7b97\u4e4b\u524d\u8fdb\u884c\u4e86\u5224\u65ad\uff09<\/p>\n<p>\u8981\u5224\u65ad\u0394\u662f\u4e0d\u662f\u5c0f\u4e8e0\uff0c\u5f88\u7b80\u5355\uff0c\u8bf7\u81ea\u5df1\u5199\u51fa\u4ee3\u7801\uff01<\/p>\n<p>\u4f60\u5f88\u53ef\u80fd\u4f1a\u8fd9\u6837\u5199<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n    if((B*b-4*a*c) &lt; 0)\r\n    {\r\n        printf(&quot;\u6b64\u65b9\u7a0b\u65e0\u89e3\uff01\\n&quot;);\r\n    }\r\n<\/pre>\n<p>\u7136\u800c\u8fd9\u6837\u7684\u8bdd\uff0c\u5728\u663e\u793a\u65b9\u7a0b\u65e0\u89e3\u540e\u8fd8\u4f1a\u7ee7\u7eed\u6267\u884c\u4e0b\u9762\u7684\u8bed\u53e5\uff0c\u4e5f\u5c31\u662f\u8bf4nan\u4f9d\u7136\u4f1a\u663e\u793a\u51fa\u6765\uff0c\u4f60\u53ef\u4ee5\u8fd0\u884c\u8bd5\u4e00\u8bd5<\/p>\n<p>\u4e3a\u6b64\u4f60\u53ef\u80fd\u4f1a\u8bf4\uff0c\u6ca1\u5173\u7cfb\uff0c\u6211\u4eec\u518d\u52a0\u4e0a\u4e00\u6b21\u5224\u65ad\uff0c\u5982\u679c\u6709\u89e3\u518d\u663e\u793a\u7ed3\u679c<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n    if(delta &lt; 0)\r\n    {\r\n        printf(&quot;\u6b64\u65b9\u7a0b\u65e0\u89e3\uff01\\n&quot;);\r\n    }\r\n\r\n\/\/\u8ba1\u7b97\u65b9\u7a0b\u7684\u89e3\r\n    if(delta &gt;= 0)\r\n    {\r\n        x1=(-b+sqrt(b*b-4*a*c))\/(2*a);\r\n        x2=(-b-sqrt(b*b-4*a*c))\/(2*a);\r\n\r\n        printf(&quot;x1=%g\\tx2=%g\\n&quot;, x1, x2);\r\n    }\r\n<\/pre>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u6b63\u5e38\u6267\u884c\u4e86<\/p>\n<p>\u4f46\u662f\u91cd\u590d\u505a\u8fd9\u79cd\u5224\u65ad\u662f\u5f88\u6d6a\u8d39\u65f6\u95f4\u7684\u4e8b\u60c5\uff0c\u8fd9\u91cc\u663e\u7136\u53ea\u6709\u4e24\u79cd\u60c5\u51b5\uff1a<\/p>\n<ol>\n<li>\u0394\u5c0f\u4e8e0\u00a0\u00a0\u00a0\u00a0 \u65e0\u89e3<\/li>\n<li>\u0394\u5927\u4e8e\u7b49\u4e8e0 \u6709\u89e3<\/li>\n<\/ol>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u7b2c\u4e8c\u79cd\u60c5\u51b5\u6b63\u597d\u662f\u7b2c\u4e00\u79cd\u60c5\u51b5\u76f8\u53cd\u7684\u65b9\u5411<\/p>\n<p>\u8fd9\u65f6\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528else<\/p>\n<p>\u5b83\u7684\u683c\u5f0f\u7c7b\u4f3c\u4e0e\u8fd9\u6837<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nif(xxx)\r\n{\r\nyyy;\r\n}\r\nelse\r\n{\r\nzzz;\r\n}\r\n<\/pre>\n<p>\u5982\u679cxxx\u7684\u7ed3\u679c\u4e3a\u771f\uff0c\u90a3\u4e48\u5c31\u6267\u884cif\u5185\u7684yyy\uff0c\u5426\u5219\u5c31\u6267\u884celse\u5185\u7684zzz<\/p>\n<p>\u8fd9\u6837\u6211\u4eec\u7684\u7a0b\u5e8f\u5c31\u6210\u4e86\u8fd9\u6837<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;math.h&gt;\r\n\/\/ sqrt(double);\r\n\r\nint main()\r\n{\r\n    double a, b, c, x1, x2;     \/\/abc\u4e3a\u65b9\u7a0b\u7684abc\uff0cx1\u548cx2\u7528\u4e8e\u4fdd\u5b58\u65b9\u7a0b\u7684\u6839\r\n    double delta;\r\n    \/\/\u5148\u8f93\u5165\u6570\u636e\r\n    printf(&quot;\u8bf7\u8f93\u5165a:&quot;);\r\n    scanf(&quot;%lf&quot;, &amp;a);\r\n    printf(&quot;\u8bf7\u8f93\u5165b:&quot;);\r\n    scanf(&quot;%lf&quot;, &amp;b);\r\n    printf(&quot;\u8bf7\u8f93\u5165c:&quot;);\r\n    scanf(&quot;%lf&quot;, &amp;c);\r\n\r\n    printf(&quot;\u6b63\u5728\u8ba1\u7b97\u65b9\u7a0b%gx^2 + %gx + %g = 0 \u7684\u6839\uff01\\n&quot;, a, b, c);\r\n\r\n    \/\/\u8ba1\u7b97\u0394\u7684\u503c\r\n    delta = b*b-4*a*c;\r\n\r\n    \/\/\u5224\u65ad\u65b9\u7a0b\u662f\u5426\u6709\u89e3\r\n    if(delta &lt; 0)\r\n    {\r\n        printf(&quot;\u6b64\u65b9\u7a0b\u65e0\u89e3\uff01\\n&quot;);\r\n    }\r\n\r\n\/\/\u6709\u89e3\u624d\u8ba1\u7b97\u65b9\u7a0b\u7684\u89e3\r\n    if(delta &gt;= 0)\r\n    {\r\n        x1=(-b+sqrt(delta))\/(2*a);\r\n        x2=(-b-sqrt(delta&lt;span id=&quot;transmark&quot;&gt;&lt;\/span&gt;))\/(2*a);\r\n\r\n        printf(&quot;x1=%g\\tx2=%g\\n&quot;, x1, x2);\r\n    }\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u9664\u4e86\u7b2c\u4e8c\u4e2aif\uff0c\u7a0b\u5e8f\u4e2d\u8fd8\u65b0\u589e\u4e86\u4e00\u4e2a\u53d8\u91cf\uff0c\u7528\u4e8e\u4fdd\u5b58delta\u7684\u503c\uff0c\u56e0\u4e3a\u7a0b\u5e8f\u4e2d\u591a\u6b21\u7528\u5230\u4e86delta\uff0c\u5982\u679c\u6bcf\u4e00\u6b21\u90fd\u7b97\u4e00\u6b21\u7684\u8bdd\uff0c\u4e0d\u4ec5\u5199\u7740\u70e6\uff0c\u7a0b\u5e8f\u7684\u6548\u7387\u4e5f\u4e0d\u9ad8<\/p>\n<p>\u663e\u7136\u4f7f\u7528else\u4f7f\u7a0b\u5e8f\u903b\u8f91\u7b80\u5355\u4e86\u4e00\u4e9b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u9762\u6211\u4eec\u5b66\u4e60\u4e86if\u8bed\u53e5\uff0c\u6211\u4eec\u5df2\u7ecf\u53ef\u4ee5\u5b9e\u73b0\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u53bb\u63a7\u5236\u7a0b\u5e8f\u8fd0\u884c\u7684\u65b9\u5411\u7684\u529f\u80fd\u4e86\u3002\u4f46\u662f\u4f3c\u4e4e\u53ea\u6709\u4e00\u4e2aif\u6709\u70b9\u4e0d\u592a\u2026 <span class=\"read-more\"><a href=\"https:\/\/yangwang.hk\/?p=442\">Read More: 3.2\u3001if\u7684\u5bf9\u9762 \u2026 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-442","post","type-post","status-publish","format-standard","hentry","category-c"],"views":1791,"_links":{"self":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts\/442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=442"}],"version-history":[{"count":3,"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts\/442\/revisions"}],"predecessor-version":[{"id":455,"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts\/442\/revisions\/455"}],"wp:attachment":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}