Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease.
Given the number of rows of the Rhombus, the task is to print Mirrored Rhombus Star pattern in C, C++, and Python.
Examples:
Example1:
Input:
given number of rows of the rhombus =8
Output:
********
********
********
********
********
********
********
********Example2:
Input:
Given number of rows of the rhombus =8 Given character to print ='<'
Output:
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<Program to Print Mirrored Rhombus Star Pattern in C, C++, and Python
Below are the ways to print mirrored Rhonbus star Patterns in C, C++, and Python.
Method #1: Using For loop (Star Character)
Approach:
- Give the number of rows of the rhombus as static input and store it in a variable.
- Loop till the number of rows of the rhombus using For loop.
- Iterate till the first iterator using another For loop(Nested For loop).
- Print the space character in the inner for loop.
- Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
- Print the star character in this inner loop with the space character.
- Print the newline character after the end of two nested for loops.
- The Exit of the Program.
1) Python Implementation
Below is the implementation:
# Give the number of rows of the rhombus as static input and store it in a variable.
rhombusrows = 8
# Loop till the number of rows of the rhombus using For loop.
for m in range(rhombusrows):
# Iterate till the first iterator using another For loop(Nested For loop).
for n in range(m):
# Print the space character in the inner for loop.
print(' ', end='')
# Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
for o in range(rhombusrows):
# Print the star character in this inner loop with the space character.
print('*', end='')
# Print the newline character after the end of two nested for loops.
print()
Output:
********
********
********
********
********
********
********
********2) C++ Implementation
Below is the implementation:
#include <iostream>
using namespace std;
int main()
{
// Give the number of rows of the rhombus as static
// input and store it in a variable.
int rhombusrows = 8;
// Loop till the number of rows of the rhombus using For
// loop.
for (int m = 0; m < rhombusrows; m++) {
// Iterate till the first iterator using another For
// loop(Nested For loop).
for (int n = 0; n < m; n++) {
// Print the space character in the inner for
// loop.
cout << " ";
}
// Loop till the number of rows of the rhombus using
// For loop(Second Nested For loop).
for (int r = 0; r < rhombusrows;
r++) { // Print the star character in this
// inner loop with the space character.
cout << "* ";
}
// Print the newline character after the end of two
// nested for loops.
cout << endl;
}
return 0;
}Output:
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *3) C Implementation
Below is the implementation:
#include <stdio.h>
int main()
{
// Give the number of rows of the rhombus as static
// input and store it in a variable.
int rhombusrows = 8;
// Loop till the number of rows of the rhombus using For
// loop.
for (int m = 0; m < rhombusrows; m++) {
// Iterate till the first iterator using another For
// loop(Nested For loop).
for (int n = 0; n < m; n++) {
// Print the space character in the inner for
// loop.
printf(" ");
}
// Loop till the number of rows of the rhombus using
// For loop(Second Nested For loop).
for (int r = 0; r < rhombusrows;
r++) { // Print the star character in this
// inner loop with the space character.
printf("* ");
}
// Print the newline character after the end of two
// nested for loops.
printf("\n");
}
return 0;
}Output:
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *Method #2: Using For loop (User Character)
Approach:
- Give the number of rows of the rhombus as user input and store it in a variable.
- Give the character to print as user input and store it in a variable.
- Loop till the number of rows of the rhombus using For loop.
- Iterate till the first iterator using another For loop(Nested For loop).
- Print the space character in the inner for loop.
- Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
- Print the given character in this inner loop with the space character.
- Print the newline character after the end of two nested for loops.
- The Exit of the Program.
1) Python Implementation
- Give the number of rows of the rhombus as user input using int(input()) and store it in a variable.
- Give the Character as user input using input() and store it in another variable.
Below is the implementation:
# Give the number of rows of the rhombus as user input using int(input()) and store it in a variable.
rhombusrows = int(input(
'Enter some random number of rows of rhombus = '))
# Give the Character as user input using input() and store it in another variable.
givencharacter = input('Enter some random character = ')
# Loop till the number of rows of the rhombus using For loop.
for m in range(rhombusrows):
# Iterate till the first iterator using another For loop(Nested For loop).
for n in range(m):
# Print the space character in the inner for loop.
print(' ', end='')
# Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
for o in range(rhombusrows):
# Print the givencharacter in this inner loop with the space character.
print(givencharacter, end='')
# Print the newline character after the end of two nested for loops.
print()
Output:
Enter some random number of rows of rhombus = 8
Enter some random character = <
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<2) C++ Implementation
- Give the number of rows of the rhombus as user input using cin and store it in a variable.
- Give the Character as user input using cin and store it in another variable.
Below is the implementation:
#include <iostream>
using namespace std;
int main()
{
// Give the number of rows of the Right
// Rhombbus as user input using cin and store it in a
// variable.
int rhombusrows;
char givencharacter;
cout << "Enter some random number of rows of the "
"Rhombus = "
<< endl;
cin >> rhombusrows;
// Give the Character as user input using cin and store
// it in another variable.
cout << "Enter some random character = " << endl;
cin >> givencharacter;
cout << endl;
// Loop till the number of rows of the rhombus using For
// loop.
for (int m = 0; m < rhombusrows; m++) {
// Iterate till the first iterator using another For
// loop(Nested For loop).
for (int n = 0; n < m; n++) {
// Print the space character in the inner for
// loop.
cout << " ";
}
// Loop till the number of rows of the rhombus using
// For loop(Second Nested For loop).
for (int r = 0; r < rhombusrows;
r++) { // Print the givencharacter in this
// inner loop with the space character.
cout << givencharacter<<" ";
}
// Print the newline character after the end of two
// nested for loops.
cout << endl;
}
return 0;
}Output:
Enter some random number of rows of rhombus =
8
Enter some random character =
<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<3) C Implementation
- Give the number of rows of the Rhombus as user input using scanf and store it in a variable.
- Give the Character as user input using scanf and store it in another variable.
Below is the implementation:
#include <stdio.h>
int main()
{
// Give the number of rows of the Rhombus
// as user input using scanf and store it in a
// variable.
int rhombusrows;
char givencharacter;
// Give the Character as user input using scanf and
// store it in another variable.
scanf("%d", &rhombusrows);
scanf("%c", &givencharacter);
printf("\n");
// Loop till the number of rows of the rhombus using For
// loop.
for (int m = 0; m < rhombusrows; m++) {
// Iterate till the first iterator using another For
// loop(Nested For loop).
for (int n = 0; n < m; n++) {
// Print the space character in the inner for
// loop.
printf(" ");
}
// Loop till the number of rows of the rhombus using
// For loop(Second Nested For loop).
for (int r = 0; r < rhombusrows;
r++) { // Print the givencharacter in this
// inner loop with the space character.
printf("%c ", givencharacter);
}
// Print the newline character after the end of two
// nested for loops.
printf("\n");
}
return 0;
}Output:
8<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<
<<<<<<<<Related Programs:
- python program to print hollow mirrored rhombus star pattern
- python program to print rhombus star pattern
- python program to print hollow rhombus star pattern
- python program to print mirrored right triangle star pattern
- python program to print reverse mirrored right triangle star pattern
- python program to print mirrored half diamond star pattern
- java program to print hollow mirrored rhombus star pattern