国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

遞歸、遍歷、冒泡

2019-11-14 16:19:01
字體:
供稿:網(wǎng)友

1.一列數(shù)的規(guī)則如下: 1、1、2、3、5、8、13、21、34...... 求第30位數(shù)是多少, 用遞歸算法實現(xiàn)。
public class TuZi
    {
        public int TZ(int x)
        {
            if (x == 1 || x == 2)
            {
                return 1;
            }
            else
            {
                return TZ(x - 1) + TZ(x - 2);
            }
        }
    }
    class PRogram
    {
        static void Main(string[] args)
        {
            TuZi a = new TuZi();
            Console.WriteLine(a.TZ(12));
        }
    }


2.遍歷頁面上所有的textbox頁面并將它賦值為string.empty?
foreach (System.Windows.Forms.Control item in this.Controls)
            {
                if (item is System.Windows.Forms.TextBox)
                {
                    System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)item;
                    tb.Text = string.Empty;
                }
            }
control類是所有控件的基類

3.實現(xiàn)一個冒泡排序算法
int[] arr = { 10, 29, 30, 40, 5 };
            for (int i = arr.Length; i >= 2;i-- )
            {
                for (int j = 0; j <i - 1;j++ )
                {
                    if (arr[j] < arr[j + 1])
                    {
                        int temp = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = temp;                  
                    }              
                }   
            }
            foreach (int item in arr)
            {
                Console.Write(item+" ");
                
            }
            Console.Read();


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 鸡西市| 杭锦后旗| 台山市| 陇南市| 大埔区| 禹城市| 兴国县| 乳山市| 文山县| 吉木萨尔县| 乌拉特后旗| 枞阳县| 灌南县| 那坡县| 灌南县| 河曲县| 岢岚县| 那曲县| 江油市| 福泉市| 长沙县| 项城市| 海安县| 建宁县| 广汉市| 汽车| 云阳县| 古蔺县| 高雄市| 甘肃省| 武安市| 朔州市| 鹿邑县| 寿光市| 柳州市| 兴城市| 安陆市| 兴国县| 玛纳斯县| 巨鹿县| 泸定县|