I need help with a program. I have to write a recursive function to print a right triangle such as this (for n == 4):
*
* *
* * *
* * * *
n is the length of foundation. I may not use loops, global variables, or the static keyword.
So far I have a program printing n:
#include <stdlib.h>
void triangle(int n);
int main() {
int n;
printf("Write n: ");
scanf("%d", &n);
triangle(n);
return 0;
}
void triangle(int n) {
if (n != 0) {
triangle(n - 1);
printf("%d", n);
printf("\n");
}
}
So how can I print a triangle like this, and will be my program helpful for doing this task?