Pyramid Number Decreasing Order:
Here in this pattern printing, the number of lines of the pattern is taken as the input. Three for loops are used to display the pattern. The first for loop (the outer for loop) is used to count the line number so the loop is from n to 1. the first inner for loop is used to print the space before printing the elements of each line. for ith line the numbers are printed from i to n.
INPUT: the number of lines
OUTPUT: the aforesaid pattern
PROCESS:
Step 1: read n [the number of lines]
Step 2: set sp<-n-1
for i=n to 1 repeat
For k=1 to sp repeat
Print “ “
For j=i to n repeat
Print j and a space
[End of ‘for’ loop]
Move to the next line
Set sp<-sp-1
[End of ‘for’ loop]
Step 3: stop.
for(i=n;i>=1;i--)--------------------------------- n
{ for(k=1;k<=sp;k++)------------------ sp
printf(" ");
for(j=i;j<=n;j++)---------------------- n-i+1
printf("%d ",j);
printf("\n");
sp--; }
The complexity is: O(n*(sp+n-i+1))=O()
Related