B
Brendan
Hi I am new to c# and working through a problem in a book:
Design and develop a program that prints the following diamond shape.
You may use output statements that print a single asterisk ( * ), a
single space or a single newline character. Maximize your use of
repetition ( with nested loop structures) and minimize the number of
output statements.
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
Ive got so far;
static void Main(string[] args)
{
int count=0, print=0;
while(count<6)
{
print = count + 1;
while(print>1)
{
printstar();
print--;
}
Console.WriteLine(" ");
count++;
}
while(count>0)
{
print = count + 1;
while(print>1)
{
printstar();
print--;
}
Console.WriteLine(" ");
count--;
}
Console.WriteLine(count);
Console.WriteLine(print);
}
static void printstar()
{
Console.Write("*");
}
which produces the following output -
*
**
***
****
*****
******
*****
****
***
**
*
I am stuck on producing the diamond shape and aligning all the start
centered in the dos console.
Can some please help me with the code or even just the algorithm to
produce it.
Thanks
Design and develop a program that prints the following diamond shape.
You may use output statements that print a single asterisk ( * ), a
single space or a single newline character. Maximize your use of
repetition ( with nested loop structures) and minimize the number of
output statements.
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
Ive got so far;
static void Main(string[] args)
{
int count=0, print=0;
while(count<6)
{
print = count + 1;
while(print>1)
{
printstar();
print--;
}
Console.WriteLine(" ");
count++;
}
while(count>0)
{
print = count + 1;
while(print>1)
{
printstar();
print--;
}
Console.WriteLine(" ");
count--;
}
Console.WriteLine(count);
Console.WriteLine(print);
}
static void printstar()
{
Console.Write("*");
}
which produces the following output -
*
**
***
****
*****
******
*****
****
***
**
*
I am stuck on producing the diamond shape and aligning all the start
centered in the dos console.
Can some please help me with the code or even just the algorithm to
produce it.
Thanks