Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
[ad_1]
On this article, we’ll discover ways to print the sample G utilizing stars and white-spaces. Given a quantity n, we’ll write a program to print the sample G over n strains or rows.
Examples:
Enter : 7 Output : *** * * * *** * * * * *** Enter : 9 Output : ***** * * * * *** * * * * * * *****
On this program, we’ve got used the easy logic of iteration over strains to create the sample G. Please have a look at the picture beneath which represents the sample G within the type of a 2-d matrix, the place mat[i][j] = ‘ij’:
If we attempt to analyze this image with a (row, column) matrix and the circles symbolize the place of stars within the sample G, we’ll be taught the steps. Right here we’re performing the operations column-wise. So for the primary line of stars, we set the primary if situation, the place the row place with 0 and (n-1) received’t get the celebrities and all different rows from 1 to (n-1), will get the celebrities. Equally, for the second, third and fourth column we would like stars on the place row = 0 and row = (n-1). The opposite steps are self-explanatory and will be understood from the place of rows and columns within the diagram.
Beneath is the implementation of above thought:
|
Output:
*** * * * *** * * * * ***
Time Complexity: O(n2), the place n represents the given enter.
Auxiliary House: O(1), no additional house is required, so it’s a fixed.
Please refer full article on Program to print the sample ‘G’ for extra particulars!
[ad_2]