C#递归

有一组数,1,1,2,3,5,8,……,用递归算法算出第三十个数

 1 using System;
 2 
 3 namespace ConsoleApp1
 4 {
 5     class Program
 6     {
 7         static void Main(string[] args)
 8         {
 9             int sLeft = 1, sRight = 1, sum = 0, count = 28;  //sLeft 为每次递归左边的值,sRight为每次递归右边的值,sum为寄存总值的变量,count为循环次数
10             while (count >= 1) 
11             {
12                 sum = sLeft + sRight;
13                 sLeft = sRight;
14                 sRight = sum;
15                 count--;
16                 Console.WriteLine(sum);
17             }
18         }
19     }
20 }

 

C#递归

上一篇:C#1.0


下一篇:C# ReaderWriterLockSlim 源码