亚洲喷奶水中文字幕电影,日本aⅴ高清一区二区三区,欧美亚洲日本国产,欧美日韩亚洲中文字幕

<legend id="flx4p"><abbr id="flx4p"><thead id="flx4p"></thead></abbr></legend>

<mark id="flx4p"><thead id="flx4p"></thead></mark>

      我要投稿 投訴建議

      C++語句學習小結

      時間:2022-07-20 19:18:37 句子 我要投稿
      • 相關推薦

      C++語句學習小結

        一、順序語句

      C++語句學習小結

        二、條件,分支語句

        1、if語句

        關鍵是能夠熟練運用 if的嵌套。要考慮好所有的情況。

        如果說 條件是兩種情況相互對應的,那么就可以只用 if 與else 。但必須要想好 每個else 跟哪個if是一對。

        如果情況是相互獨立的三種情況以上,那么可以選擇運用if ... else if ...else。

        1.if語句

        if(條件)

        {

        滿足條件的時候執(zhí)行;

        }

        2. if(條件)

        {

        滿足條件執(zhí)行;

        }

        else

        {

        不滿足條件時執(zhí)行;

        }

        3 if(條件1)

        {

        滿足條件1的時候執(zhí)行;

        }

        else if(條件2)

        {

        不滿足條件1的情況下滿足條件2;

        }

        4.

        if(條件1)

        {

        if(條件2)

        {

        既滿足條件1又滿足條件2的時候執(zhí)行;

        }

        }

        2、switch 語句

        如果說可選的條件比較多時,選擇switch語句,要比if語句效率要高。特別注意的是 case 后跟的break。

        eg:

        //eg.6 swtich語句 作用域

        static void Maine(string[] args)

        {

        //Console.WriteLine("你本次選擇出場的英雄是:");

        Random r = new Random();

        int n = r.Next(10);

        string a;

        switch (n)

        {

        case 1:

        a = "趙信"; break;

        case 2:

        a = "寒冰射手";break;

        case 3:

        a = "無極劍圣";break;

        case 4:

        a = "機器人"; break;

        default:

        a = "齊天大圣";break;

        }

        Console.WriteLine("本次選擇的英雄是:"+a);

        }

        三、循環(huán)語句

        for循環(huán)

        四要素:

        初始條件,循環(huán)條件,狀態(tài)改變,循環(huán)體。 執(zhí)行過程:

        初始條件--循環(huán)條件--循環(huán)體--狀態(tài)改變--循環(huán)條件....

        注意:for的小括號里面分號隔開,for的小括號后不要加分號。

        利用 加斷點的方式,可以更好的明白for的工作原理。

        1.for循環(huán)空操作完成的實例, 輸出100以內的數(shù)字

        static void Main(string[] args) { int i = 1; for (; ; ) { if (i > 100) { break; } Console.Write(i + "t"); i++; } Console.ReadKey(); }

        當然你也可以用 while,if() break;的嵌套完成上述操作。

        .正序和逆序的推斷問題。 (折紙問題)

        //eg.5 折紙問題

        static void Maine(string[] args) { //Console.WriteLine("請輸入次數(shù)"); //int n = Convert.ToInt32(Console.ReadLine()); //int i = 0; //for (double sum = 0.0001; sum <= sum="" double="" int="" z="0;" for="" i="0;" if="">= 8848.0) { Console.WriteLine(z); break; } } }

        b.迭代法:有一定規(guī)律。 每次循環(huán)都是從上次運算結果中獲得數(shù)據(jù),本次運算的結果都是要為下次運算做準備。

        eg1 兔生兔問題

        有一對幼兔,幼兔一個月后成長為小兔,小兔一個月后成長為成兔并生下一對幼兔,問幾年后有多少對兔子,其中幼兔,小兔,成兔分別是多少?

        //eg.2 兔生兔問題

        //方法一 static void Maink3(string[] args) { int syt = 1, byt = 0; int sxt = 0, bxt = 0; int sct = 0, bct = 0; Console.WriteLine("請輸入月數(shù):"); int month = Convert.ToInt32(Console.ReadLine()); int sum; for (int i = 1; i <= month; i++) { //賦值順序不能變,必須按照兔子生長規(guī)律來,先有的bct才會有byt bct = sxt + sct; bxt = syt; byt = sxt + sct; //bct = sxt + sct; 這樣寫,必須注意他的順序 //bxt = syt; //byt = bct; //byt = bct;//錯誤的 //bxt = syt; //bct = sxt + sct; syt = byt; sxt = bxt; sct = bct; //sum = byt + bxt + bct; } sum = byt + bxt + bct; Console.WriteLine("過了{0}個月后,幼兔個數(shù)為{1}對,小兔個數(shù)為{2}對,成兔個數(shù)為{3}對,總共有{4}對。", month.ToString(), byt, bxt, bct,sum); } //方法二 static void Maink4(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); int tu = 0;//要求那個月的總數(shù) int tu1=1, tu2=1;//倒數(shù)第一個為 tu1,倒數(shù)第二個為 tu2 for (int i = 3; i < n;i++ ) { tu = tu1 + tu2; tu2 = tu1; tu1 = tu; } Console.WriteLine(tu); } //方法三 static void Maink5(string[] args) { Console.Write("請輸入月數(shù):"); int m = int.Parse(Console.ReadLine()); int ct = 0;//成兔的對數(shù) int xt = 0;//小兔的對數(shù) int yt = 1;// int zt = 1;// for (int i = 1; i <= m; i++) { if (i == 1) { ct = 0; xt = 0; yt = 1; } else { ct = xt + ct; xt = yt; yt = ct; } zt = yt + xt + ct; Console.WriteLine(i.ToString() + "個月后成兔的對數(shù)是:" + ct.ToString()); Console.WriteLine(i.ToString() + "個月后小兔的對數(shù)是:" + xt.ToString()); Console.WriteLine(i.ToString() + "個月后幼兔的對數(shù)是:" + yt.ToString()); Console.WriteLine(i.ToString() + "個月后兔子的總對數(shù)是:" + zt.ToString()); } Console.ReadLine(); }

        eg 2 100以內的所有數(shù)的和。

        eg3. 求階乘。

        eg4.求年齡。

        eg5.折紙。

        eg6.棋盤放糧食。

        eg7.猴子吃桃子。

        static void Maink(string[] args) { int sum = 1; for (int i = 0; i < 6; i++) { int t = (sum + 1) * 2; sum = t; } Console.WriteLine("桃子一共有:" + sum + "個。"); }

        eg8.落球問題。一個球從10米高度落下,每次彈起2/3的高度,問第五次彈起后的高度?

        四、while 循環(huán)。一般用在一些死循環(huán)當中。

        五、try catch。保護程序,避免程序出錯時無法運行。

        格式:

        try//快捷方式:雙擊 tab鍵 { } catch (Exception) { throw; } finally { }

        以上所述就是本文的全部內容了,希望大家能夠喜歡。

      【C++語句學習小結】相關文章:

      C++面試試題09-25

      聯(lián)想C++筆試題09-25

      華為C++筆試題09-25

      C/C++面試試題09-26

      搜狗2017 C++筆試題09-25

      中興通訊C++/C筆試題09-26

      C++程序員經(jīng)典筆試題09-26

      鼓勵學習的語句09-03

      學習勵志語句06-19

      鼓勵自己學習的經(jīng)典語句08-04