Skip to content

Instantly share code, notes, and snippets.

@GReturn
Last active February 19, 2024 11:31
Show Gist options
  • Save GReturn/2e3e3f9500b32398cf1bb2503c24124e to your computer and use it in GitHub Desktop.
Save GReturn/2e3e3f9500b32398cf1bb2503c24124e to your computer and use it in GitHub Desktop.
Print a pyramid - Recursive Implementation
#include <stdio.h>
void printSpaces(int spaceIndex)
{
if(spaceIndex == 0) return;
printf(" ");
return printSpaces(spaceIndex-1);
}
void printStars(int starIndex)
{
if(starIndex == 0) return;
printf("*");
return printStars(starIndex-1);
}
void printRow(int row, int starCount)
{
if(row==0) return;
printSpaces(row-1);
printStars(starCount);
printf("\n");
return printRow(row-1, starCount+2);
}
void printPyramid(int height)
{
return printRow(height, 1);
}
int main(int argc, char const *argv[])
{
printPyramid(9);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment