C++ program to print pattern of stars till N number of rows
While pattern programs are just based on a couple of logic statements, with a repeating pattern on every iteration, they are quite tricky to code. You must have heard about the triangular pyramid pattern, which prints a character in a pyramid fashion.
Generally these patterns are represented with "*" symbol. However, you can always use the character of your choice.
Consider the program:
Output
Starting with the variables, we have used a space variable that will count the space, rows variable that will hold the number of rows. The i and k variables are loop counters.
After taking rows input from the user, we start a loop to traverse all the rows. Inside it, we use another for loop with space variable in it. This is to ensure that on every row, there are i characters and (row-i) spaces. Next, we check while k is not equal to twice the rows minus 1, we put a star symbol and increment the k.
After the loop we reset k=0 and print a new line.
need an explanation for this answer? contact us directly to get an explanation for this answer