C#: Display the pattern like a diamond
C# Sharp For Loop: Exercise-31 with Solution
Write a program in C to display the pattern like a diamond.
The pattern is as follows :
* *** ***** ******* ********* ******* ***** *** *

Sample Solution:-
C# Sharp Code:
using System;
public class Exercise31
{
public static void Main()
{
int i,j,r;
Console.Write("\n\n");
Console.Write("Display the pattern like diamond:\n");
Console.Write("-----------------------------------");
Console.Write("\n\n");
Console.Write("Input number of rows (half of the diamond) :");
r = Convert.ToInt32(Console.ReadLine());
for(i=0;i<=r;i++)
{
for(j=1;j<=r-i;j++)
Console.Write(" ");
for(j=1;j<=2*i-1;j++)
Console.Write("*");
Console.Write("\n");
}
for(i=r-1;i>=1;i--)
{
for(j=1;j<=r-i;j++)
Console.Write(" ");
for(j=1;j<=2*i-1;j++)
Console.Write("*");
Console.Write("\n");
}
}
}
Sample Output:
Display the pattern like diamond: ----------------------------------- Input number of rows (half of the diamond) :8 * *** ***** ******* ********* *********** ************* *************** ************* *********** ********* ******* ***** *** *
Flowchart:

C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C# Sharp Program to find the Armstrong number for a given range of number.
Next: Write a C# Sharp Program to determine whether a given number is prime or not.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook