※ 引述《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