嵌套的C#循环 [英] nested C# loops
本文介绍了嵌套的C#循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获得这种形状-
I am trying to get this shape -
*****
****
***
**
*
但相反,我不能减一.有人可以帮帮我吗?这是我的代码-
*****
****
***
**
*
but instead, I am not able to decrement to one. Can someone please help me? this is my code-
推荐答案
安迪卡斯,
这是您的示例代码:
Hi andykas,
Here is code for your example:
Console.WriteLine("Enter number of rows ");
noOfRows = Convert.ToInt32(Console.ReadLine());
for (int index = noOfRows; index > 0; index--){
for (int c = 0; c < index; c++)
Console.Write("*");
Console.WriteLine(); //new line after each row
}
Console.WriteLine(); //new line after pattern
最好的问候!
Best regards!
这篇关于嵌套的C#循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文