CREATE OWN LIBRARY

Solid Right Star Rhombus

Back to Programming

Description

Solid Rhombus Right

 

*********

 *********

  *********

   *********

    *********

     *********

      *********

       *********

        *********

 

For printing the aforesaid pattern the number of lines is taken as input. The number of stars in each line is the same as the number of lines of the pattern. That means if there are n number of lines then there are n number of stars at each line. the number of spaces before printing the stars is n-i for ith line (the line number is counted here in reverse order i.e. the value of i decreases after every iteration). Three for loops are used here, the outer for loop is used to count the number of lines. The first inner for loop is used to print the spaces before the star at each line. The second inner for loop is used to print the stars of each line.

Algorithm

INPUT: the number of lines
OUTPUT: the aforesaid pattern
PROCESS:
Step 1: [taking the input]
	Read n [number of lines]
Step 2: [printing the pattern]
	For i=n to 1 repeat
For j=1 to n-I repeat
			Print " "
		[End of ‘for’ loop]
		For k=1 to n repeat
			Print "*"
		[End of ‘for’ loop]
		Move to the next line
	[End of ‘for’ loop]
Step 3: Stop.

Code

Time Complexity:

for(i=n;i>=1;i--)---------------------------------------- n

                {     //printing the spaces

                                for(j=1;j<=n-i;j++)--------------------------- n-i

                                                printf(" ");

                                //printing the stars

                                for(k=1;k<=n;k++)---------------------------- n

                                                printf("*");

                                printf("\n");      }

 

The complexity of this program is: O(n*(n-i+n))=O(n2)