Program to print mirror image of Swastika Pattern
Given the number of rows and columns, print the mirror image of swastika pattern.
Note : The number of rows and columns should be same and an odd number. This will generate a perfect mirror image of swastika pattern.
Examples :
Input : row = 5, col = 5
Output :
* * * *
* *
* * * * *
* *
* * * *
Input : row = 9, col = 9
Output :
* * * * * *
* *
* *
* *
* * * * * * * * *
* *
* *
* *
* * * * * *
Below is the implementation to print the mirror image of swastika pattern.
C++
// C++ implementation to print // mirror image of swastika pattern. #include <bits/stdc++.h> using namespace std; // function to print mirror image of swastika void revswastika(int row, int col) { for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { // for the upper half of the Swastika if (i < row / 2) { // checking if j < col/2 if (j < col / 2) { // the first quadrant will have // stars till half the number of rows if (i == 0 && i < row / 2) cout << "*" << " "; // rest will have spaces else cout << " " << " "; } // the middle line of the swastika else if (j == col / 2) cout << "*"; else { // the second quadrant of the // upper half will have spaces if (i < row / 2 && j < col - 1) cout << " " << " "; if (j == col - 1) // only the last column of the // second quadrant will have stars cout << " " << "*"; } } // for the lower half of the Swastika // the middle horizontal line of the // Swastika will be at row/2 else if (i == row / 2) cout << "*" << " "; else { // for stars in the third quadrant // and the middle line of the lower Swastika if (j == col / 2 || j == 0) cout << "*" << " "; else if (i == row - 1) { // the last row's third quadrant // will have spaces and the fourth // will have stars if (j <= col / 2 || j == col) cout << " " << " "; else cout << "*" << " "; } // rest of the remaining portion // will have spaces all along else cout << " " << " "; } } cout << "\n"; } } // Driver code int main() { // same no. of rows and columns to // get the perfect mirror image // of swastika pattern. int row = 9, col = 9; // function calling revswastika(row, col); return 0; } |
chevron_right
filter_none
Java
// Java implementation to print // mirror image of swastika pattern. import java.io.*; class GFG { // function to print mirror image of swastika static void revswastika(int row, int col) { for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { // for the upper half of the Swastika if (i < row / 2) { // checking if j < col/2 if (j < col / 2) { // the first quadrant will have // stars till half the number of rows if (i == 0 && i < row / 2) System.out.print("*" + " "); // rest will have spaces else System.out.print(" " + " "); } // the middle line of the swastika else if (j == col / 2) System.out.print("*"); else { // the second quadrant of the // upper half will have spaces if (i < row / 2 && j < col - 1) System.out.print(" " + " "); if (j == col - 1) // only the last column of the // second quadrant will have stars System.out.print(" " + "*"); } } // for the lower half of the Swastika // the middle horizontal line of the // Swastika will be at row/2 else if (i == row / 2) System.out.print("*" + " "); else { // for stars in the third quadrant // and the middle line of the lower Swastika if (j == col / 2 || j == 0) System.out.print( "*" + " "); else if (i == row - 1) { // the last row's third quadrant // will have spaces and the fourth // will have stars if (j <= col / 2 || j == col) System.out.print (" " + " "); else System.out.print("*" + " "); } // rest of the remaining portion // will have spaces all along else System.out.print(" " + " "); } } System.out.println(); } } // Driver code public static void main (String[] args) { // same no. of rows and columns to // get the perfect mirror image // of swastika pattern. int row = 9, col = 9; // function calling revswastika(row, col); } } // This code is contributed by vt_m. |
chevron_right
filter_none
Python3
# Python3 implementation to print # mirror image of swastika pattern. # Function to print mirror image of swastika def revswastika(row, col): for i in range(row): for j in range(col): # for the upper half of the Swastika if (i < row // 2): # checking if j < col/2 if (j < col // 2): # The first quadrant will have # stars till half the number of rows if (i == 0 and i < row // 2): print("* ", end = "") # rest will have spaces else: print(" ", end = " ") # the middle line of the swastika elif (j == col // 2): print("*", end = "") else: # the second quadrant of the # upper half will have spaces if (i < row // 2 and j < col - 1): print(" ", end = " ") if (j == col - 1): # only the last column of the # second quadrant will have stars print(" *", end = "") # For the lower half of the Swastika # the middle horizontal line of the # Swastika will be at row/2 elif (i == row // 2): print("* ", end = "") else: # For stars in the third quadrant and # the middle line of the lower Swastika if (j == col // 2 or j == 0): print("* ", end = "") elif (i == row - 1): # last row's third quadrant will # have spaces and fourth will have stars if (j <= col // 2 or j == col): print(" ", end = " ") else: print("* ", end = "") # rest of the remaining portion # will have spaces all along else: print(" ", end = " ") print() # Driver code # same no. of rows and columns to # get the perfect mirror image # of swastika pattern. row = 9; col = 9 revswastika(row, col) # This code is contributed by Azkia Anam. |
chevron_right
filter_none
C#
// C# implementation to print mirror // image of swastika pattern. using System; class GFG { // function to print mirror image // of swastika static void revswastika(int row, int col) { for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { // for the upper half of the // Swastika if (i < row / 2) { // checking if j < col/2 if (j < col / 2) { // the first quadrant // will have stars till // half the number of // rows if (i == 0 && i < row / 2) Console.Write("*" + " "); // rest will have spaces else Console.Write(" " + " "); } // the middle line of the // swastika else if (j == col / 2) Console.Write("*"); else { // the second quadrant of // the upper half will // have spaces if (i < row / 2 && j < col - 1) Console.Write(" " + " "); if (j == col - 1) // only the last column // of the second quadrant // will have stars Console.Write(" " + "*"); } } // for the lower half of the Swastika // the middle horizontal line of the // Swastika will be at row/2 else if (i == row / 2) Console.Write("*" + " "); else { // for stars in the third quadrant // and the middle line of the // lower Swastika if (j == col / 2 || j == 0) Console.Write( "*" + " "); else if (i == row - 1) { // the last row's third quadrant // will have spaces and the fourth // will have stars if (j <= col / 2 || j == col) Console.Write(" " + " "); else Console.Write("*" + " "); } // rest of the remaining portion // will have spaces all along else Console.Write(" " + " "); } } Console.WriteLine(); } } // Driver code public static void Main () { // same no. of rows and columns to // get the perfect mirror image // of swastika pattern. int row = 9, col = 9; // function calling revswastika(row, col); } } // This code is contributed by vt_m. |
chevron_right
filter_none
PHP
<?php // PHP code to print Mirror // image of swastika pattern. // function to print // mirror image of swastika function revswastika($row, $col) { for ($i = 0; $i < $row; $i++) { for ($j = 0; $j < $col; $j++) { // for the upper half // of the Swastika if ($i < floor($row / 2)) { // checking if j < $col/2 if ($j < floor($col / 2)) { // the first quadrant will // have stars till half the // number of $rows if ($i == 0 && $i < floor($row / 2)) echo "*" . " "; // rest will have spaces else echo " " . " "; } // the middle line // of the swastika else if ($j == floor($col / 2)) echo "*"; else { // the second quadrant of the // upper half will have spaces if ($i < floor($row / 2) && $j < $col - 1) echo " " . " "; if ($j == $col - 1) // only the last $column // of the second quadrant // will have stars echo " " . "*"; } } // for the lower half of the Swastika // the middle horizontal line of the // Swastika will be at $row/2 else if ($i == floor($row / 2)) echo "*" . " "; else { // for stars in the third // quadrant and the middle // line of the lower // Swastika if ($j == floor($col / 2) || $j == 0) echo "*" . " "; else if ($i == $row - 1) { // the last $row's third // quadrant will have spaces // and the fourth will have // stars if ($j <= floor($col / 2) || $j == $col) echo " " . " "; else echo "*" . " "; } // rest of the remaining // portion will have spaces // all along else echo " " . " "; } } echo "\n"; } } // Driver code // same no. of $rows and $columns // to get the perfect mirror image // of swastika pattern. $row = 9; $col = 9; // function calling revswastika($row, $col); // This code is contributed by mits ?> |
chevron_right
filter_none
Output :
* * * * * *
* *
* *
* *
* * * * * * * * *
* *
* *
* *
* * * * * *
Recommended Posts:
- Program to Print Mirror Image of Sine-Wave Pattern
- Program to print Swastika Pattern
- Program for triangular pattern (mirror image around 0)
- Program to print the given H Pattern
- Program to print the pattern 'G'
- Program to print the pattern "GFG"
- Program to print pattern
- Program to print the given Z Pattern
- Program to print the pattern ‘D’
- Program to print pyramid pattern
- Program to print a rectangle pattern
- Program to print Crown Pattern
- Program to print interesting pattern
- Program to print numeric pattern
- Program to print Step Pattern
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar



