实现代码
private static int Calu(int number){ var sum = 0; if (number % 2 == 0) sum = -(number / 2); else sum = -(number - 1) / 2 + number; return sum;}
代码调用
private static void Main(string[] args){ Console.WriteLine(Calu(1)); Console.WriteLine(Calu(2)); Console.WriteLine(Calu(3)); Console.WriteLine(Calu(4)); Console.WriteLine(Calu(5)); Console.WriteLine(Calu(6)); Console.ReadLine();}