給出1組30個數字的前5個數:11235,找到規律輸出這30個數及生成的30個數中的奇數.偶數的個數.
阿新 • • 發佈:2019-01-28
namespace shangji2 { class Class1 { public int[] HanShu() { int[] shu = new int[30]; shu[0] = 1; shu[1] = 1; for (int i = 2; i < 30;i++ ) { shu[i] = shu[i - 1] + shu[i - 2]; } foreach (var t in shu) { Console.WriteLine(t); } return shu; } public void g(ref int o,ref int p) { int[] shu = HanShu(); foreach(int item in shu ){ if (item % 2 == 0) { o++; } else { p++; } } } } namespace shangji2 { class Program { static void Main(string[] args) { Class1 d = new Class1(); d.HanShu(); int o=0; int p=0; d.g(ref o, ref p); Console.WriteLine("奇數個數:{0},偶數個數:{1}",o,p); Console.ReadLine(); } }