dispaly the numbers dimond formate using c#

Posted by Naidulaxmi under ASP.NET on 10/1/2014 | Points: 10 | Views : 398 | Status : [Member] | Replies : 1
Hi friends,

For example enter the 5 in the text box then display the diamond shape like this below


1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
plz help me,

thanks,

appalanaidu


Responses

Posted by: A2H on: 10/5/2014 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can try with the below code
//Code to print number in format

//1
//22
//333
//4444
//55555
//Loop through number from 1 to 5
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
//Print out the numbers
Console.Write(i);
}
//Print out the new line
Console.WriteLine();
}

//Code to print number in format
//4444
//333
//22
//1
for (int i = 5; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
Console.Write(i);
}
Console.WriteLine();
}


You can find a working sample in below link
https://dotnetfiddle.net/vz05yn

Thanks,
A2H
My Blog

Naidulaxmi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response