Hi everybody. I'm in my first programming course ever and have a few questions about an assignment that we've been given.
I'm trying to print the following pattern to the screen:
The pattern is supposed to contain 5 rows and each subsequent row has 2 additional asterisks from the row above making roughly a pyramid shape.
I've been working on creating code to do this using For loops (this was part of the instructions) and here's what I have so far:
Code:#include <stdio.h> int main () { int row; int col; for (row = 1; row <= 5; row++) //rows { for (col = 1; col <= row; col++) //columns { printf_s("*"); } printf_s("\n"); } return 0; }
The problem with my code is that I am not accounting for the required empty spaces to get the alignment correct. With the above current code here's what the output looks like:
I'm hoping someone can point me in the right direction as to how to re-write my code to get the correct alignment.
Thank you in advance.