C# 递归算法与冒泡

时间:2023-08-11 17:37:14

C# 递归算法求 1,1,2,3,5,8,13···
static void Main(string[] args)
{

int[] cSum = new int[10];
for (int i = 0; i < cSum.Length; i++)
{
cSum[i] = Pro_WriteNum(i);
Console.WriteLine(cSum[i]);
}
Console.ReadLine();
}

private static int Pro_WriteNum(int a)
{
int result = 0;
if (a == 0 || a == 1)
{
result = 1;
}
else
{
result = Pro_WriteNum(a - 1) + Pro_WriteNum(a - 2);
}
return result;

}
-------------------------------------------------------------
int temp;
int[] arrSort = new int[] { 10, 8, 3, 5, 6, 7, 9 };
for (int i = 0; i < arrSort.Length; i++)
{
for (int j = i + 1; j < arrSort.Length; j++)
{
if (arrSort[j] < arrSort[i])
{
temp = arrSort[j];
arrSort[j] = arrSort[i];
arrSort[i] = temp;
}
}
}