CREATE OWN LIBRARY

Number Pattern 20

Back to Programming

Description

Number Pattern:

For printing the aforesaid pattern, the number of lines is taken as input. Two for loops are used to print the pattern. The outer for loop is used to count the number of lines and the inner for loop is used to print the pattern. The number of elements of ith line is also i.

Algorithm

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

Code

Time Complexity:

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

                {

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

                                                printf("%d ",(int)pow(j,i));

                                printf("\n");

                }

 

The complexity is: O(n*i)=O(n2)