Junter.wjs STUST MIS 丙 4A990025
Learn More →
public partial class Form1 : Form
{
string s;
private void button1_Click(object sender, EventArgs e)
{
int start, max, step, i, sum = 0;
start = Convert.ToInt32(textBox1.Text);
max = Convert.ToInt32(textBox2.Text);
step = Convert.ToInt32(textBox3.Text);
label8.Text = "";
s = "數列為:";
if (step < 0)
{
if (start < max)
{
MessageBox.Show("由小到大,等差須為正值", "錯誤!", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
else
{
for (i = start; i >= max; i += step)
{
sum -= i;
s += i + " ";
}
s += "\n" + "總和為:" + Math.Abs(sum);
label8.Text = s;
}
}
else
{
if (start > max)
{
MessageBox.Show("由大到小,等差須為負值", "錯誤!", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
else
{
for (i = start; i <= max; i += step)
{
sum += i;
s += i + " ";
}
s += "\n" + "總和為:" + Math.Abs(sum);
label8.Text = s;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
int start, max, step, sum = 0;
start = Convert.ToInt32(textBox1.Text);
max = Convert.ToInt32(textBox2.Text);
step = Convert.ToInt32(textBox3.Text);
label8.Text = "";
s = "數列為:";
if (step < 0)
{
if (start < max)
{
MessageBox.Show("由小到大,等差須為正值", "錯誤!", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
else
{
do
{
sum += start;
s += start + " ";
start += step;
} while (start >= max);
s += "\n" + "總和為:" + Math.Abs(sum);
label8.Text = s;
}
}
else
{
if (start > max)
{
MessageBox.Show("由大到小,等差須為負值", "錯誤!", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
else
{
do
{
sum += start;
s += start + " ";
start += step;
} while (start <= max);
s += "\n" + "總和為:" + Math.Abs(sum);
label8.Text = s;
}
}
}
private void button3_Click(object sender, EventArgs e)
{
int start, max, step, sum = 0;
start = Convert.ToInt32(textBox1.Text);
max = Convert.ToInt32(textBox2.Text);
step = Convert.ToInt32(textBox3.Text);
label8.Text = "";
s = "數列為:";
if (step < 0)
{
if (start < max)
{
MessageBox.Show("由小到大,等差須為正值", "錯誤!", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
else
{
while (start >= max)
{
sum += start;
s += start + " ";
start += step;
}
s += "\n" + "總和為:" + Math.Abs(sum);
label8.Text = s;
}
}
else
{
if (start > max)
{
MessageBox.Show("由大到小,等差須為負值", "錯誤!", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
else
{
while (start <= max)
{
sum += start;
s += start + " ";
start += step;
}
s += "\n" + "總和為:" + Math.Abs(sum);
label8.Text = s;
}
}
}
個人資料
經歷:
未來目標:
職業
課業
成就
不知道可以幹嘛的證照:
程式碼如有錯誤!請自行修正。
C#
For
do..while
while
Loop
迴圈
Copyright © 2020 Junter.Inc All Rights Reserved
change h1, h2, h3, h4 and p, strong, ins。`{%hackmd @Junter0323/H14LvIwHu %}`
May 30, 2022:::success 共三層,每層 ≥ 2子classes 每一classes ≥ 1 var + 1 method 用word or pdf 印出 ::: ::: danger
Nov 1, 2021最新公告 :::success 完成作業ㄧ、二 ::: 上課平台 ::: info
Oct 28, 20211.每股盈餘 2.稀釋性 3.母公司淨利 4.本期淨利 5.非控制權益 6.營業利益 7.營業活動之淨現金 (現金流量表) 8.綜合損益 9.流動資產 10.資產總計 (網站)
Apr 20, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up