用C#输出菱形(费解中......)?
*************************最后结果不是我问题那样显示,应该是菱形的...
*
***
*****
*******
*****
***
*
最后结果 不是我问题那样显示,应该是 菱形的 展开
***
*****
*******
*****
***
*
最后结果 不是我问题那样显示,应该是 菱形的 展开
6个回答
展开全部
我帮你解答,这个可以输入数字,然后输出菱形,如果输入的不是数字,会报错然后要求从新输入。如果输入end,则会提示程序结束。
//No.6_菱形的输出
int HS = 0;//HS就是输入的行数
string input = "";
bool isright = false;
do
{
try
{
Console.WriteLine("输入行数");
input = Console.ReadLine();
HS = Convert.ToInt32(input);
for (int ZXCS = 1; ZXCS <= (HS + 1) / 2; ZXCS++)//ZXCS是执行次数
{
for (int KG = 1; KG <= (HS - (ZXCS * 2 - 1)) / 2; KG++)//xs+2*kg=hs,而xs=(zxcs*2-1)
{
Console.Write(" ");
}
for (int XS = 1; XS <= ZXCS * 2 - 1; XS++)//XS输出的星星数
{
Console.Write("*");
}
Console.WriteLine();
}
for (int ZXCS1 = 1; ZXCS1 <= (HS - 1) / 2; ZXCS1++)
{
for (int KG1 = 1;KG1<=ZXCS1; KG1++)
{
Console.Write(" ");
}
for (int XS1=1; XS1<=HS-2*ZXCS1;XS1++ )
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadKey();
}
catch
{
if (input != "end")
{
Console.WriteLine("输入错误");
//input = Console.ReadLine();
}
else
{
Console.WriteLine("OVER");
isright = true;
}
}
}
while (isright == false);
Console.ReadKey();
//No.6_菱形的输出
int HS = 0;//HS就是输入的行数
string input = "";
bool isright = false;
do
{
try
{
Console.WriteLine("输入行数");
input = Console.ReadLine();
HS = Convert.ToInt32(input);
for (int ZXCS = 1; ZXCS <= (HS + 1) / 2; ZXCS++)//ZXCS是执行次数
{
for (int KG = 1; KG <= (HS - (ZXCS * 2 - 1)) / 2; KG++)//xs+2*kg=hs,而xs=(zxcs*2-1)
{
Console.Write(" ");
}
for (int XS = 1; XS <= ZXCS * 2 - 1; XS++)//XS输出的星星数
{
Console.Write("*");
}
Console.WriteLine();
}
for (int ZXCS1 = 1; ZXCS1 <= (HS - 1) / 2; ZXCS1++)
{
for (int KG1 = 1;KG1<=ZXCS1; KG1++)
{
Console.Write(" ");
}
for (int XS1=1; XS1<=HS-2*ZXCS1;XS1++ )
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadKey();
}
catch
{
if (input != "end")
{
Console.WriteLine("输入错误");
//input = Console.ReadLine();
}
else
{
Console.WriteLine("OVER");
isright = true;
}
}
}
while (isright == false);
Console.ReadKey();
展开全部
for(int i=1;i<5;i++){
for(int j=1;j<=5-i;j++)
Console.Write(" ");
for(int k=1;k<=i*2-1;k++)
Console.Write("*");
Console.WriteLine("");
}
for(int i=1;i<=3;i++){
for(int j=0;j<=i;j++)
Console.Write(" ");
for(int k=1;k<=7-2*i;k++)
Console.Write("*");
Console.WriteLine("");
调试过 很成功
for(int j=1;j<=5-i;j++)
Console.Write(" ");
for(int k=1;k<=i*2-1;k++)
Console.Write("*");
Console.WriteLine("");
}
for(int i=1;i<=3;i++){
for(int j=0;j<=i;j++)
Console.Write(" ");
for(int k=1;k<=7-2*i;k++)
Console.Write("*");
Console.WriteLine("");
调试过 很成功
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string s1=" * ";
string s2=" *** ";
string s3=" ***** ";
string s4=" ******* ";
string s5=" ********* ";
string s6=" ******* ";
string s7=" ***** ";
string s8=" *** ";
string s9=" * ";
console.writeLine(s1);
console.writeLine(s2);
console.writeLine(s3);
console.writeLine(s4);
console.writeLine(s5);
console.writeLine(s6);
console.writeLine(s7);
console.writeLine(s8);
console.writeLine(s9);
空格打不出来
string s2=" *** ";
string s3=" ***** ";
string s4=" ******* ";
string s5=" ********* ";
string s6=" ******* ";
string s7=" ***** ";
string s8=" *** ";
string s9=" * ";
console.writeLine(s1);
console.writeLine(s2);
console.writeLine(s3);
console.writeLine(s4);
console.writeLine(s5);
console.writeLine(s6);
console.writeLine(s7);
console.writeLine(s8);
console.writeLine(s9);
空格打不出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这种算法,主要是考虑下每一行的符号和它所在行数的关系,楼主只要搞清楚这个关系,剩下的就是两个for循环嵌套。
建议不要一上来就要源码,搞清楚实现的思路,比源码重要多了。
建议不要一上来就要源码,搞清楚实现的思路,比源码重要多了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace regularEx
{
class Program
{
static void Print(int number, int max)
{
if (number < max)
{
string line = "";
for (int i = 0; i < (max - number) / 2; i++)
line += " ";
for (int i = 0; i < number; i++)
line += "*";
Console.WriteLine(line);
Print(number + 2, max);
Console.WriteLine(line);
}
else
{
string line = "";
for (int i = 0; i < number; i++)
line += "*";
Console.WriteLine(line);
}
}
static void Main(string[] args)
{
Print(1, 9);
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace regularEx
{
class Program
{
static void Print(int number, int max)
{
if (number < max)
{
string line = "";
for (int i = 0; i < (max - number) / 2; i++)
line += " ";
for (int i = 0; i < number; i++)
line += "*";
Console.WriteLine(line);
Print(number + 2, max);
Console.WriteLine(line);
}
else
{
string line = "";
for (int i = 0; i < number; i++)
line += "*";
Console.WriteLine(line);
}
}
static void Main(string[] args)
{
Print(1, 9);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询