Hollow Rhombus Star Pattern Program In C | Patterns

Hollow Rhombus star pattern program in C. Here is the program to find the rhombus star pattern in C. The following program has been written in three different ways using for loop, using while loop, and using do while loop. If you do have any method other than this three, you can leave a code right over after the program.

Also, check out the sample outputs, sample programs below.

1.Using For Loop

  1. Read the number of rows and store that value into the variable n, read the entered symbol using getchar() function and store it in the variable ch.

2) The outer for loop iterates through rows from i=1 to n with the structure for(i=1;i<=n;i++).

3) The 1st inner for loop iterates through columns from j=1 to n-i with the structure for(j=1;j<=n-i;j++) and prints space.

4) The 2nd inner loop iterates through columns from j=1 to n with the structure for(j=1;j<=n;j++) and prints symbol for i=1 or n.

5) For i!=1 or i!=n, the 3rd inner loop iterates through columns from j=1 to n.

a) Prints symbol if j=1 or n.b) Otherwise it print space.

6) Cursor comes to next line for each iteration of i.

 

Output:

2.Using While Loop

  1. The outer while loop iterates through rows until the condition i<=n becomes false.

2) The 1st inner while loop iterates through columns and prints space until the condition j++<=n-i becomes false.

3) For i=1 or n the 2nd inner while loop iterates through columns and prints symbol until the condition j<=n becomes false.

4) At remaining rows other than 1,n.The 3rd inner while loop iterates through columns until the condition j<=n becomes false.

a) Prints symbol if j=1 or n.b) Otherwise prints space.

5)Cursor comes to next line for each iteration of the outer while loop.

 

Output:

3.Using Do-While Loop

  1. For i=1 the outer do-while loop iterates one time.

2) a) For j=1 the 1st inner do-while loop prints one space.

b) j value increased by 1.

c) Checks the condition j++<=n-i.If the condition is true then loop iterates through column again.Repeats until the condition becomes false.

3) If i=1 or n(1st row or nth row)

a) The 2nd inner do-while loop prints one symbol for j=1.

b) j value increased by 1.

c) Checks the condition ++j<=n.If the condition is true then loop iterates once through the column.Repeats until the condition becomes false.

4) If i!=1 or i!=n (other than 1t row, last row)

a) The 3rd inner do-while loop prints one character if j=1 or n.Otherwise, it prints space.

b) j value increased by 1.

c) Checks the condition ++j<=n.If the condition is true loop iterates once.Repeats until the condition becomes false.

5) Cursor comes to next line for each iteration.

6) a) i value increased by 1.

b) Checks the condition i<=n.If the condition true loop iterates once.Repeats until the condition becomes false.

Output:

 

Add a Comment

Your email address will not be published. Required fields are marked *