Introduction
In this post, I am going to explain how to make a Swastik in the c language. For writing this program, you must know how to use a loop and if-else statement. Before writing the program, let us see the expected output.

As you can see in the above diagram, there are stars as well as blank spaces. This is nothing but a matrix that contains rows and columns.
In this above output, I have taken 5 rows and 5 columns. You can take any odd number matrix.
Now, let us see the actual c program to make Swastik.
C Program to Make Swastik
#include <stdio.h> #include <stdlib.h> int main() { int i,j,row=5,col=5; for(i=0;i<row;i++) { for(j=0;j<col;j++) { if(i<row/2) { if(j<col/2) { if(j==0) printf("*"); else printf(" "); } else if(j==col/2) printf(" *"); else { if(i == 0) printf(" *"); } } else if(i==row/2) printf("* "); else { if((j==col/2)||(j==(col-1))) printf("* "); else if(i==(row - 1)) { if((j<=col/2)||(j==col-1)) printf("* "); else printf(" "); } else printf(" "); } } printf("\n"); } return 0; }
Go through this program and you will get the above output. I hope there is no problem for you to understand this program. If you have any problems, then kindly let me know.
Thank you.
Important C Programs
- Program in C to Find Longest Line in a File
- Palindrome in C using Pointers
- Insert and Delete element in Array in C using switch case
- C Program to Add Alternate Elements of a 2D Array
- Arrays in C for Complete Beginners
- C Program to Find Area of a Circle using Preprocessor
- Program in C to Remove White Spaces and Comments from a File
- C Program to Print Numbers Except Multiples of n
- Reverse a Number using getchar and putchar function in c
- The while loop in C Programming