作者habit22 (呆呆狗)
看板C_Sharp
标题Re: [问题] 请问一个简单的C#入门程式(累加次数计算)
时间Thu Apr 9 23:47:01 2009
※ 引述《powerplay (小气鬼喝凉水)》之铭言:
: namespace ConsoleApplication27
: {
: class Program
: {
: static void Main(string[] args)
: {
: int a, b, c = 0;
: Console.Write("请输入累加次数:");
: a = Int32.Parse(Console.ReadLine());
: for (b = 1; b <= a; b++)
: c = c + b;
: Console.Write("累加结果=" + c);
: Console.ReadLine();
: }
: }
: }
static void Main(string[] args)
{
Console.WriteLine("请输入累加:");
string str = Console.ReadLine();
string index = "";
int num = 0;
for (int i = 1; i <= Int32.Parse(str); i++)
{
num += i;
if (index=="")
index = i.ToString();
else
index += "+" + i.ToString();
}
Console.WriteLine(index + "=" + num);
Console.ReadLine();
}
应该是这样吧...
我也是初学者~
共勉之吧~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.194.147.173