Hey @urban lodge ! I think your question would get better motion in the channel #1084551836817698906 but let's take down your doubt right now.
First things first, I tested your code and it works like a charm but you are right, recursive functions are less efficient and more resources demanding than for loops for certain things.
I did it in a different way, by using just a for loop and a function to repeat the characters. I also added a verification for height greater than 8, to prevent that thing printing '#' until the end of times by a wrong input. Check if that's still a requirement for the problem because, if so, you'll need it for passing the check.
As your solution is already good, sharing is caring and not against the code of conduct. This is how I did it:
#include <cs50.h>
#include <stdio.h>
void repeat(char a, int t);
int main(void)
{
int height;
do
{
height = get_int("Height: ");
}
while (height < 1 || height > 8);
for (int i = 1; i <= height; i++)
{
repeat(' ', height - i);
repeat('#', i);
printf(" ");
repeat('#', i);
printf("\n");
}
}
void repeat(char a, int t)
{
for (int i = 0; i < t; i++)
{
printf("%c", a);
}
}
I'm pretty sure there are much more optimized ways to do it than mine, but it works 😆 and that's what you need at the point you are.
That course is amazing, I did it until the HTML/CSS/JavaScript part, where I plan to return later. The most complicated part is all the C units, but you will gain a strong fundamental understanding of how any program language works under the hood.