Mirrored Rhombus Star Pattern Program In c | Patterns

Mirrored Rhombus Star Pattern Program In C Programming. Here is the list of three different ways in Star pattern programs on Mirrored Rhombus Star. The following code has been written in three different ways using for loop, while loop, and using do while loop.

Also, check out the sample outputs, and sample program. At the end of the post, we do list out the more C programs and also online execution tool for you. Do check it out.

1.Using For Loop

  1. Read the no.of rows, store the value into the variable n, read the entered symbol 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=i to 1 with the structure for(j=i;j>0;j–).

a) Prints space.

4) For i=1 or n(1st row or nth row)

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

5) For i!=1 or i!=n(other than 1st row,nth row)

The 3rd inner for loop iterates through columns with the structure for(j=1;j<=n;j++)

a) prints symbol if j=1 or j=n

b) Otherwise it prints space.

6) The cursor comes to next line for each iteration.

 

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>0 becomes false.

3) For i=1 or n(1st row,nth row)

The 3rd inner while loop iterates through columns until the condition j<=n

a) Prints symbol.

4) for i!=1 or i!=n(for other than 1st row,nth row)

The 4th inner while loop iterates through columns until the condition j<=n becomes false.

a) Prints symbol if j=1 or j=n

b) Otherwise it print space.

5) For each iteration of the outer while-loop cursor comes to next line.

Output:

3.Using Do-While Loop

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

2) a) For j=i the 1st inner do-while loop iterates through columns and print one space.

b) j value decreased by 1.

c) Checks the condition –j>0.If condition true loop iterates again.Repeats until the condition becomes false.

3) a) For j=1 the 2nd inner do-while loop iterates through columns and prints one character.

b) j value increased by 1.

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

4) Cursor comes to next line.

5) a) i value increased by 1.

b) Checks the condition i<=n.If the condition is true then outer do-while loop iterate again.Repeats until the condition becomes false.

Output:

 

Add a Comment

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