I've just started the CS50 course and currently having no coding experience I feel like I am doing 'OK' however I am trying to complete a side task of creating a 'right aligned pyramid' having already completed the left aligned one I thought this would be easy, but I am struggling to get my head around what needs to be done.
can you help - ideally looking for an update on the code and how that affects the outcome, rather than just an answer, as i'd like to understand the change and reasoning.
#include \<cs50.h\>
#include \<stdio.h\>
void print_row(int length);
int main(void)
{
int height = get_int("Height: ");
for (int i = 0; i \< height; i++)
{
print_row(i + 1);
}
}
void print_row(int length)
{
for (int g = 0 ; g \< length; g++)
{
printf(" ");
}
for (int h = 0; h \< length; h++)
{
printf("#");
}
printf("\\n");
}
I realize that you were wanting just some directions in the comments and not a full answer, but since I did not seem to convey the thought process here, let me offer up a refactored version of the code for printing a pyramid for a requested height based upon the code you included. Following is the refactored code.
Here are some of the points I was trying to talk about as also noted in the comments.
Following was a quick sample test with what I believe is the desired output based upon previous "print a pyramid" questions I have worked on.
The takeaway I see here probably is to delve more into available "C" tutorial literature, either published or online, and get more familiar with things such as the backslash escape combo's.