

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print a diamond using nested loop using C#?
With C#, you can easily display the following diamond shape.
$ $$$ $$$$$ $$$$$$$ $$$$$$$$$ $$$$$$$ $$$$$ $$$ $
To display a diamond shape, you need to focus on the following points −
Number of rows Dollar sign to be displayed Empty spaces
Considering the above you can easily create the diamond shape as shown in the below code −
Example
using System; namespace Program { public class Demo { public static void Main(String[] args) { int i, j, r, d, e; // rows = 5 r = 5; // display dollar sign d = 1; // empty space e = r - 1; for (i = 1; i < r * 2; i++) { // display empty space for (j = 1; j <= e; j++) Console.Write(" "); for (j = 1; j < d * 2; j++) Console.Write("$"); Console.WriteLine(); if (i < r) { e--; d++; } else { e++; d--; } } } } }
Output
$ $$$ $$$$$ $$$$$$$ $$$$$$$$$ $$$$$$$ $$$$$ $$$ $
- Related Questions & Answers
- How to print the stars in Diamond pattern using C language?
- C program to print four powers of numbers 1 to 9 using nested for loop
- A nested loop puzzle?
- Print a pattern without using any loop in C++
- How to print a name multiple times without loop statement using C language?
- Java Program to print Number series without using any loop
- C program to print number series without using any loop
- C program to print multiplication table by using for Loop
- Java Program to print the diamond shape
- C++ Program to print the diamond shape
- Python Program to print the diamond shape
- Program to print Diamond Pattern in C
- Java Program to Print Diamond Star Pattern
- Program to print numbers from 1 to 100 without using loop
- How to print a one-month calendar of user choice using for loop in C?
Advertisements