# CREATE OWN LIBRARY

## Diagonal and sides of a rectangle Star Pattern

Back to Programming

### Description

Diagonal and sides of a rectangle Star Pattern

For printing the pattern the number of lines is taken as input. For printing, this pattern the number of lines should be odd. So after taking the number of lines as input checking is done. If it is odd, then only the pattern can be printed else an error message is shown. The stars are only printed on the boundary line and on the diagonal lines of a rectangle.

### Algorithm

``````INPUT: number of lines
OUTPUT: the aforesaid pattern
PROCESS:
Step 1: [taking the input]
Read n [number of lines]
Step 2: [printing the pattern]
If n mod 2≠0 then
For i=0 to n-1 repeat
For j=0 to n-1 repeat
If i=0 or j=0 or i=j or i=n-1 or j=n-1 or i+j=n-1 then
Print "*"
Else
Print “ “
[End of ‘if’]
[End of ‘for’ loop]
Move to the next line
[End of ‘for’ loop]
else
print “Please give correct input(no. of lines should be odd)"
[End of ‘if]
Step3: Stop.
``````

## Time Complexity:

for (i=0;i<n;i++)------------------------------------ n

{    for(j=0;j<n;j++)--------------------------- n

{   if(i==0||j==0||i==j||i==n-1||j==n-1||i+j==n-1)

printf("*");

else

printf(" "); }

printf("\n");

}

The complexity is: O(n*n)=O(${\mathrm{n}}^{2}$)