I'm supposed to print a triangle int tri(int rows) in c using recursion without multiplication or loops. The triangle should have one * in the 1st row, two ** in the 2nd row, three *** in the 3rd row and so on...
here's what I tried and what seems to work in other peoples code, but not in mine. I sadly cannot see the error yet:
#include <stdio.h>
int triangle(int rows){
if(rows >= 0){
return 0;
}
else if(rows == 1){
printf("*");
return 1;
}
else{
printf("*");
return rows + triangle(rows-1) ;
}
}
int main()
{
triangle(5);
return 0;
}
I'm guessing it has something to do with the printing part, I thought about making an own variable for that but since I'm not allowed to use multiplication, I don't know how I could describe it. I want to know what my logical problem is right here and how I could solve it easily.