Hollow Diamond Pattern in CIntroduction:Programmers write a lot of practice programs in the form of patterns. One of them is the diamond pattern programs. Here, we'll use C to create a hollow diamond design. Star pattern in C with hollow diamondsLet's create a C program for star pattern with hollow diamonds: Output: Enter number of rows: 7 * * * * * * * * * * * * * * * * * * * * * * * * Numbering Pattern in a Hollow Diamond:Instead of stars, this hollow diamond design has numbers. Therefore, only a small portion of the code will change, while the rest will remain unchanged. The pattern counts up from 1 to 5 starting with 1. Only 1 appears in the first and last rows, whereas exactly 2 identical numbers appear in all other rows. The size of the design increases from the first to the fifth row while decreasing from the sixth to the ninth row. Output: Input: 5 1 2 2 3 3 4 4 5 5 4 4 3 3 2 2 1 In this design, the first and last rows each have one star, and the remaining rows all have precisely two stars. Simply replace the * with another character to display any character in lieu of the stars. In this instance, though, each character must be unique. We'll employ the following 2 methods to print the hollow diamond pattern in C:
First approach: Using for LoopOutput: * * * * * * * * * * * * * * * * Another approach: Using While LoopNow we can print the hollow diamond using while loop: Output: * * * * * * * * * * * * * * * * Next TopicRegister Keyword in C |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India