Hi guys,
I'm trying to print patterns such as the following:
****
***
**
*
**
***
****
using recursion. I can figure out the code for the top half and the bottom half seperately. i.e i can print
****
***
**
*
and
*
**
***
****
each recursively. I'm trying to combine these into one function. How could I call the functions so that I could combine the two?
here are my functions
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> void printTriangle (int n) { if (n==1) {printf("*"); printf("\n"); } else if(n>1) { int i; for (i=0;i<n;i++) printf("*"); printf("\n"); printTriangle(n-1); } } void printInvertedTriangle(int n) { if (n==1) {printf("*"); printf("\n"); } else if(n>1) { printInvertedTriangle(n-1); int i; for (i=0;i<n;i++) printf("*"); printf("\n"); } } int main(void) {printInvertedTriangle(4); }