[級數項(1, −2, 3, −4, …)不趨近於0,因此通過項測試便可確定1 − 2 + 3 − 4 + …發散。不過作為後文的參考,此處也以基礎的方法去證明此級數發散。首先,從定義可知,無窮級數的斂散性是由其部分和的斂散性所確定的,1 − 2 + 3 − 4 + …的部分和為: 1 = 1, 1 ...
實現代碼
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();
}