How to Make Swastik in C Language?

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.

how to make swastik in c language

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

  1. Program in C to Find Longest Line in a File
  2. Palindrome in C using Pointers
  3. Insert and Delete element in Array in C using switch case
  4. C Program to Add Alternate Elements of a 2D Array
  5. Arrays in C for Complete Beginners
  6. C Program to Find Area of a Circle using Preprocessor
  7. Program in C to Remove White Spaces and Comments from a File
  8. C Program to Print Numbers Except Multiples of n
  9. Reverse a Number using getchar and putchar function in c
  10. The while loop in C Programming

Leave a Comment