日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

经典代码收集

發布時間:2025/3/21 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 经典代码收集 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? /// <summary>

??? /// 數學界把這個數列叫做斐波那契數列

??? /// 112358132134...... 求第n位數是多少

??? /// n 由用戶輸入

??? /// </summary>

??? class Program

??? {

??????? static void Main(string[] args)

??????? {

??????????? string s = Console.ReadLine();

??????????? int num;

??????????? if (int.TryParse(s, out num))

??????????????? Console.WriteLine("結果是: {0}", countFibonacci(num));

??????????? else

??????????????? Console.WriteLine("無效的輸入...");

??????????? Console.ReadLine();

??????? }?

??????? static int countFibonacci(int n)

??????? {

?? ? ? ? ??if (n < 2)

??????????????? return n;

??????????? return countFibonacci(n - 1) + countFibonacci(n - 2);

??????? }

??????? //countFibonacci(n - 1)求出它的前一個數

??????? //countFibonacci(n - 2)求出它的前的第二個數

??? }

?? ? ? ?/// <summary>

??????? /// 字符串反轉的算法

??????? /// </summary>

??????? /// <param name="str"></param>

??????? /// <returns></returns>

??????? public static string Reverse(string str)

??????? {

??????????? if (string.IsNullOrEmpty(str))

??????????? {

??????????????? throw new ArgumentException("參數不合法");

??????????? }

??????????? //當使用StringBuilder時,請注意,應在構造StringBuilder對象時指明初始容量,

??????????? //否則默認容量是16個字符,當由于追加字符而超出默認容量時,

??????????? //就會分配一個新的串緩沖區,大小是原緩沖區的兩倍

??????????? StringBuilder sb = new StringBuilder(str.Length);

?

??????????? for (int index = str.Length - 1; index >= 0; index--)

??????????? {

??????????????? sb.Append(str[index]);

??????????? }

??????????? return sb.ToString();

?? ? ? ?}?

?

?

?

?? ?/// <summary>

??? /// 1 加到 100 C#算法

??? /// </summary>

??? class Program

??? {

??????? static void Main(string[] args)

??????? {

??????????? int Num = 100;

??????????? int Sum = 0;

??????????? for (int i = 1, j = Num; i <= Num / 2; i++, j--)

??????????? {

??????????????? Sum += i + j;

??????????? }

??????????? Console.WriteLine(Sum.ToString());

??????????? Console.ReadLine();

??????? }

??? }

?

?

?? ?/// <summary>

??? /// 1 100 的素數

??? /// 素數:是這樣的整數,它除了能表示為它自己和1的乘積以外,

??? /// 不能表示為任何其它兩個整數的乘積

??? /// </summary>

??? class Program

??? {

??????? static void Main(string[] args)

??????? {

???????? Console.Write(2 + " ");

???????? for (int m = 3; m <= 100; m+=2)

???????? {

???????????? bool a = true;

???????????? if (m%2!=0)

???????????? {

??????????????? for (int i = 3; i < m/2; i+=2)

??????????????? {

??????????????????? if (m%i==0)

??????????????????? { a = false; break; }

??????????????? }

??????????? }

??????????? if (a == true)

??????????? {

??????????????? Console.Write(m.ToString() + " ");

??????????? }

??????? }

??????? Console.ReadLine();

??????? }

?? ?}?

轉載于:https://www.cnblogs.com/NetDeng/archive/2010/03/04/1678094.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的经典代码收集的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。