Created
February 17, 2012 16:17
-
-
Save rctay/1854184 to your computer and use it in GitHub Desktop.
[c] pyramids for CS1010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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