循环实现、统计
提示: 作者被禁止或删除 内容自动屏蔽
Console.Write("Input String:"); string input = Console.ReadLine(); int[] infos = new int[4]; infos[0] = Regex.Matches(input, "[a-zA-Z]").Count; infos[1] = Regex.Matches(input, "\\d").Count; infos[2] = Regex.Matches(input, " ").Count; infos[3] = input.Length - (infos[0] + infos[1] + infos[2]);
double result = 0; int tempnumber = 1; int tempnumb = 1; int tempsum; for (int i = 0; i < 10; i++) { tempsum = tempnumber + tempnumb; if (i % 2 == 0) { result += Convert.ToDouble(tempsum) / Convert.ToDouble(tempnumber); } else if (i % 2 == 1) { result -= Convert.ToDouble(tempsum) / Convert.ToDouble(tempnumber); } tempnumb = tempnumber; tempnumber = tempsum; }或者:
double result = 0; int tempnumber = 1; int tempnumb = 1; int tempsum; int sh = -1; for (int i = 0; i < 10; i++) { sh *= -1; tempsum = tempnumber + tempnumb; result += sh * Convert.ToDouble(tempsum) / Convert.ToDouble(tempnumber); tempnumb = tempnumber; tempnumber = tempsum; }