简单算法问题,高手快来拿走20分!先写先得啊
打印以下图案:
*****
*****
*****
*****
*****
简单算法问题,高手快来拿走20分!先写先得啊
------解决方案--------------------如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] sArray = {
"***** ",
" ***** ",
" ***** ",
" ***** ",
" ***** "
};
foreach(string i in sArray)
{
Console.WriteLine(i);
}
}
}
}
------解决方案--------------------static void Main(string[] args)
{
for(int i=0;i <5;i++)
{
for(int k=0;k <=i;k++)
{
Console.Write( " ");
}
for(int j=0;j <5;j++)
{
Console.Write( "* ");
}
Console.WriteLine( " ");
}
}
如上...
------解决方案--------------------for (int i=0;i <10;i++)
{
string a = "*** ";
a.PadLeft(i + a.Length, ' ');
MessageBox.Show(a);
}
------解决方案--------------------private void Out(string Pstr,int PnRow)
{
for(int i = 1;i <= PnRow;i++)
{
Console.WriteLine(Pstr + "\n ");
Pstr = " " + Pstr;
}
}
private void main()
{
string str = "***** "; //输出字符串
int nRow = 6; //输出行数
Out(str,nRow);
}
------解决方案--------------------private void Out(string Pstr,int n,int PnRow) //Pstr字符串,n每行的个数,PnRow行数
{
string str = " ";
for(int j = 1;j <=n;j++)
{
str += Pstr;
}
for(int i = 1;i <= PnRow;i++)
{
Console.WriteLine(str + "\n ");
str = " " + str;
}
}
private void main()
{
string str = "* "; //输出字符
int n = 5;
int nRow = 6; //输出行数
Out(str,n,nRow);
}
这个可能更好点