一楼的,计算结果不正确 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { int result = getResult(30);//从1+2-3-4+5+6-7-8....30 Console.WriteLine("1+2-3-4+5+6-7-8....30 = {0}",result); result = getResult(50);//从1+2-3-4+5+6-7-8....50 Console.WriteLine("1+2-3-4+5+6-7-8....50 = {0}", result); Console.Read(); } private static int getResult(int num) { int times = 0;//计数,每隔两个就做一次转换 int sign = 1; //符号变换 通过-1 与 1 来改变 int result = 0; //结果 for (int i = 1; i <= num; i++) { result += sign * i; times++; if (times % 2 == 0) { times = 0; sign = -sign;//如果隔两个了,就变换符号 } } return result; } } }