码迷,mamicode.com
首页 > 其他好文 > 详细

text1

时间:2017-09-16 23:14:03      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:for   .text   整数   reading   ring   text   lin   console   ext   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace text1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个正整数:");
int n = Convert.ToInt16(Console.ReadLine());
int result = 0;
if(n%2==0)
{
for(int i=0;i<=n;)
{
result = result + i;
i = i + 2;
}
Console.WriteLine("数列和为:"+result+"\n"+"输入回车结束");
}
else if(n%2!=0)
{
for(int i = 1; i <= n;)
{
result = result + i;
i = i + 2;
}
Console.WriteLine("数列和为:" + result + "\n" + "输入回车结束");
}
}
}
}

text1

标签:for   .text   整数   reading   ring   text   lin   console   ext   

原文地址:http://www.cnblogs.com/fuckman/p/7533184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!