首页 > 其他 > 详细

for练习 打印图形

时间:2015-04-01 23:12:14      阅读:166      评论:0      收藏:0      [点我收藏+]

static void Main(string[] args)
{
while (true)
{
int a, b, c;
Console.WriteLine("请选择图形:1.正方形2.三角形3.平行四边形4.菱形5.梯形");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("输入需要打印的行数:");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("输入需要打印的列数:");
c = Convert.ToInt32(Console.ReadLine());
switch (a)
{
case 1:
for (int i = 1; i <=b ; i++)
{
for (int j = 1; j <=b ; j++)
{
Console.Write("★");
}
Console.WriteLine();
}
break;
case 2:
for (int i = 1; i <=b ; i++)
{
for (int d = b-1; d >=i ; d--)
{
Console.Write(" ");

}
for (int j = 1; j <=2*i-1; j++)
{
Console.Write("★");
}
Console.WriteLine();
}
break;
case 3:
for (int i = 1; i <=b ; i++)
{
for (int d = b-1; d>=i ; d--)
{
Console.Write(" ");
}
for (int j = 1; j <=c ; j++)
{
Console.Write("★");
}
Console.WriteLine();
}
break;
case 4:
for (int i = 1; i <=b ; i++)
{

for (int d = b - 1; d >= i; d--)
{
Console.Write(" ");

}
for (int j = 1; j <= 2 * i - 1; j++)
{
Console.Write("★");

}
Console.WriteLine();
}
for (int i = 1; i<=b; i++)
{
for (int e = 0; e <= i - 1; e++)
{
Console.Write(" ");
}
for (int h = 2 * b - 3; h >= 2*i-1; h--)
{
Console.Write("★");
}
Console.WriteLine();
}

break;
case 5:
for (int i = 1; i <=b ; i++)
{

for (int j =1; j<=i+2; j++)
{
Console.Write("★");
}
Console.WriteLine();
}
break;
default:
Console.WriteLine("输入错误");
break;
}
Console.ReadLine();
}
}

for练习 打印图形

原文:http://www.cnblogs.com/happinesshappy/p/4385447.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!