<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 3.C語言while語句的用法 while語句的一般形式為: ? ? while(表達式) 語句 其中表達式是循環條件,語句為循環體。 while語句的語義是:計算表達式的值,當值為真(非0)時, 執行循環體語句。其執行過程可用下圖表示。 ![](http://www.lvtao.net/content/uploadfile/201404/51293dce23559dcc1fad42dc20daa30620140421041853.gif) 【例6-2】用while語句計算從1加到100的值。用傳統流程圖和N-S結構流程圖表示算法,見圖: ![](http://www.lvtao.net/content/uploadfile/201404/36e37b59af36b736442c1790541911da20140421041853.gif) ~~~ main(){ int i,sum=0; i=1; while(i<=100){ sum=sum+i; i++; } printf("%d\n",sum); } ~~~ 【例6-3】統計從鍵盤輸入一行字符的個數。 ~~~ #include <stdio.h> main(){ int n=0; printf("input a string:\n"); while(getchar()!='\n') n++; printf("%d",n); } ~~~ 本例程序中的循環條件為getchar()!='\n',其意義是,,只要從鍵盤輸入的字符不是回車就繼續循環。循環體n++完成對輸入字符個數計數。從而程序實現了對輸入一行字符的字符個數計數。 使用while語句應注意以下兩點。 1) while語句中的表達式一般是關系表達或邏輯表達式,只要表達式的值為真(非0)即可繼續循環。 ~~~ main(){ int a=0,n; printf("\n input n: "); scanf("%d",&n); while (n--) printf("%d ",a++*2); } ~~~ 本例程序將執行n次循環,每執行一次,n值減1。循環體輸出表達式a++*2的值。該表達式等效于(a*2; a++)。 2) 循環體如包括有一個以上的語句,則必須用{}括起來,組成復合語句。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看