Diagonal and sides of Star Diamond
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 rhombus/diamond.
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
Set u1<-(n-1)/2
Set u2<-3*n/2-1
For i=0 to n-1 repeat
For j=0 to n-1 repeat
If i+j=u1 or i-j=u1 or j-i=u1 or i+j=u2 or i=u1 or j=u1 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.
for(i=0;i<n;i++)----------------------------------------- n
{ for(j=0;j<n;j++) ------------------------------ n
{ if(i+j==u1||i-j==u1||j-i==u1||i+j==u2||i==u1||j==u1)
printf("*");
else
printf(" ");
}
printf("\n");
}
The complexity is: O(n*n)=O()
Contributed by