Inverted Full Pyramid
*******
*****
***
*
Here to print the pattern the number of lines is taken as input. Three for loops are used here to print the pattern. The outer for loop is used to count the number of lines. The number of stars of the first line is related to the number of lines of the pattern. If the number of lines is n then the number of stars of the first line is 2n-1 and it is decreased by 2 after each line. the first inner for loop is used to print the spaces before printing the stars and the loop is running from 1 to n-i for the ith line and here i is calculated in reversed order i.e. from n to 1. The 2nd inner for loop is used to print the stars.
Input: the number of lines
OUTPUT: the aforesaid pattern
PROCESS:
Step 1: [taking the input from user]
Read n [number of lines]
Step 2: [printing the pattern]
Set st<-2n-1
For i=n to 1 repeat
For j=1 to n-i repeat
Print " “
[End of ‘for’ loop]
For k=1 to st repeat
Print "*"
[End of ‘for’ loop]
Move to the next line
Set st=st-2
[End of ‘for’ loop]
Step 3: Stop.
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<=st;k++)----------------------------- st
printf("*");
printf("\n");
st-=2; }
The first ‘for’ loop is running from n to 1 and the inner for loop is running from 1 to n-i and the second loop is from 1 to st. So the time complexity is O(n*(n-i+st))=O().