{"id":308,"date":"2023-02-22T02:26:54","date_gmt":"2023-02-22T10:26:54","guid":{"rendered":"http:\/\/bitas.net.cn\/?page_id=308"},"modified":"2023-02-22T02:27:04","modified_gmt":"2023-02-22T10:27:04","slug":"107-2","status":"publish","type":"page","link":"http:\/\/bitas.net.cn\/index.php\/sourcecode\/107-2\/","title":{"rendered":"107 \u8054\u5408\u4f53\u7b80\u4ecb"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n#include &lt;stdlib.h>\n#include &lt;string.h>\n#include &lt;assert.h>\n\ntypedef union tagVxValue {\n    int per;\n    double val;\n} VxValue;\n\n#define REC_PER 0\n#define REC_VAL 1\ntypedef struct tagVx {\n    double max;\n    int rec;\n    VxValue vxv;\n} Vx; \n\ntypedef struct tagFlow {\n    double q;\n    double s;\n    double vx; \n} Flow;\n\nvoid set_flow(Flow *pf)\n{\n    if (pf)\n        pf->q = pf->s * pf->vx;\n}\n\nvoid print_flow(Flow *pf)\n{\n    if (pf) {\n        printf( \"%15s: %.2f\\n\"\n                \"%15s: %.2f\\n\"\n                \"%15s: %.2f\\n\",\n                \"S\", pf->s,\n                \"Vx\", pf->vx,\n                \"Q\", pf->q);\n        printf(\"-------------------------\\n\");\n    }   \n}\n\nint main(int argc, char *argv&#91;])\n{\n    \/\/ vx1 &amp; f1\n    Vx vx1 = { 200, REC_PER, { .per = 25 } };\n    Flow f1;\n    f1.s = 0.1;\n    f1.vx = vx1.rec ?\n        vx1.vxv.val :\n        (vx1.vxv.per \/ 100.0 * vx1.max);\n    set_flow(&amp;f1);\n    print_flow(&amp;f1);\n    \/\/ vx2 &amp; f2\n    Vx vx2 = { 200, REC_VAL, { .val = 50 } };\n    Flow f2;\n    f2.s = 0.1;\n    f2.vx = vx2.rec ?\n        vx2.vxv.val :\n        (vx2.vxv.per \/ 100.0 * vx2.max);\n    set_flow(&amp;f2);\n    print_flow(&amp;f2);\n    \/\/ f1.q should equals f2.q\n    assert(f1.q == f2.q);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":127,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-308","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/comments?post=308"}],"version-history":[{"count":1,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/308\/revisions"}],"predecessor-version":[{"id":309,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/308\/revisions\/309"}],"up":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/127"}],"wp:attachment":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/media?parent=308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}