0

Hello Friends...
I'm writing a C program to print pattern of swastik using *. I want to set my pattern in the center of the screen. Can anyone tell me how can I do this ????
Below is the C program for swastik, but it do not print swastik in the center.

#include<stdio.h>
#include<conio.h>
void main()
{
	int i,j,n;
	clrscr();
	again:
	printf("\n Enter Value for n (odd) : ");
	scanf("%d",&n);
	if(n%2==0)
		goto again;
	clrscr();
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(j==0 && i<=(n-1)/2 || j==n-1 && i>=(n-1)/2
			|| i==0 && j>=(n-1)/2 || i==n-1 && j<=(n-1)/2
			|| i==(n-1)/2 || j==(n-1)/2)
				printf("* ");
		    else
			printf("  ");
		}
		printf("\n\n");
	}
	getch();
}
2
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by avani20391
0

Figure out what the width of the screen is, divide that by 2, then subtract half of the shape's width that you're trying to print. Then before printing each row of the shape, add that many spaces.

0

I don't know, can you?

I'm trying... not succeeded yet. please tell me if you find any other option.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.