Editorial Staff - - C++ Tutorial
In this program, we are going to share a C++ implementation to print swastika pattern. If you are a beginner and want to start learning the C programming, then keep your close attention in this tutorial as I am going to share a C++ program to print swastika pattern.
To increase your C++ knowledge, practice all C++ programs:
Copy the below C++ program and execute it with the help of GCC compiler. At the end of this program, We have shared the output of this program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include <bits/stdc++.h> using namespace std; void swastika(int row, int col) { for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { if (i < row / 2) { if (j < col / 2) { if (j == 0) cout << "*"; else cout << " " << " "; } else if (j == col / 2) cout << " *"; else { if (i == 0) cout << " *"; } } else if (i == row / 2) cout << "* "; else { if (j == col / 2 || j == col - 1) cout << "* "; else if (i == row - 1) { if (j <= col / 2 || j == col - 1) cout << "* "; else cout << " " << " "; } else cout << " " << " "; } } cout << "\n"; } } int main() { int row = 7, col = 7; swastika(row, col); return 0; } |
1 2 3 4 5 6 7 8 9 | * * * * * * * * * * * * * * * * * * * * * * * * * |
Editorial Staff at FreeWebMentor is a team of professional developers leads by Prem Tiwari View all posts by Editorial Staff