这是一个简单的问题,但我仍在学习这门语言。
我们如何编写具有参数的程序,以便如果数字为 5,它将写入
*
**
***
****
*****
我能做到:
*
*
*
*
使用这个:
private void button1_Click(object sender, EventArgs e)
{
string message = " ";
for (int count = 0; count < numericUpDown1.Value; count++)
{
for (int m = 0; m < numericUpDown1.Value; count)
{
message += "*" + "\r\n";
}
}
}
我想我需要第二个 for
循环,但我不确定下一步该做什么。
最佳答案
如果这不是概念性作业,那么用这种方式解决会容易得多:
for(int i=1; i<=n; i++)
Console.WriteLine(new string('*',i));
关于c# - 使用两个 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11630081/