CREATE OWN LIBRARY

Star Matrix Pattern

Back to Programming

Description

Star Matrix Pattern: 

 

The length and breadth of the rectangle are taken as input. A solid rectangle is printed using two for loops. The outer for loop is calculating the breadth (the number of lines of the pattern) of the rectangle and the inner for loop is used for calculating the length (the elements of each line).

Algorithm

INPUT: the length and the breadth of the rectangle
OUTPUT: the aforesaid pattern
PROCESS:
Step 1: [Taking the inputs]
	Read l, b [length & breadth of the rectangle]
Step 2: [printing the pattern]
	For i=1 to b repeat
		For j=1 to l repeat 
			Print “*  “
		[End of ‘for’ loop]
	[End of ‘for’ loop]
Step 3: Stop.

Code

Time Complexity:

for(i=1;i<=b;i++)---------------------------------- b

                {              for(j=1;j<=l;j++)------------------------ l

                                                printf("*   ");

                                printf("\n");       }

The complexity is: O(b*l)=O(b2)

If we consider the variable b as n then the complexity can be written as O(n2).