Skip to content

Instantly share code, notes, and snippets.

@rctay
Created February 17, 2012 16:17
Show Gist options
  • Save rctay/1854184 to your computer and use it in GitHub Desktop.
Save rctay/1854184 to your computer and use it in GitHub Desktop.
[c] pyramids for CS1010
#include <malloc.h>
#include <string.h>
void print_pyramid(int k)
{
int i;
size_t sz = 1 + (k-1)*2;
char *buf = malloc(sizeof(char) * sz);
memset(buf, '*', sz);
for (i = 1; i < k; i++)
printf("%*.*s\n", k + i - 1, 1 + (i-1) * 2, buf);
printf("%.*s\n", sz, buf);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment