判断奇偶性数列相加
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TEST1_1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个正整数");
int n = int.Parse(Console.ReadLine());
int sum1 = 0, sum2 = 0;
if (n % 2 == 0)
{
for (int i = 0; i <= n; i += 2)
sum1 = sum1 + i;
Console.WriteLine("是偶数数列之和为{0}",sum1);
}
if(n % 2 != 0)
{
for (int j = 1; j <= n; j += 2)
sum2 = sum2 + j;
Console.WriteLine("是奇数数列之和为{0}",sum2);
}
Console.ReadLine();
}
}
}