1.1
2017-09-24 22:19 xx-- 阅读(184) 评论(0) 编辑 收藏 举报using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _1._1 { class Program { static void Main(string[] args) { int n, i, result = 0; //定义变量 Console.WriteLine("请输入一个正整数"); n = int.Parse(Console.ReadLine()); //输入整数n if (n % 2 == 0) //判断n奇偶性 i = 2; else i = 1; for (; i <= n; i += 2) //计算i+(i+2)+(i+2+2)+....+n result += i; Console.WriteLine(result); Console.WriteLine("按回车键结束"); Console.ReadLine(); } } }