Skip to content

Instantly share code, notes, and snippets.

@waggertron
Created October 1, 2018 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waggertron/2e4d623e9bf97574cfdb42f66fe4f42c to your computer and use it in GitHub Desktop.
Save waggertron/2e4d623e9bf97574cfdb42f66fe4f42c to your computer and use it in GitHub Desktop.
two loop solution
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * char_repeat( int n, char c ) {
char * dest = malloc(n+1);
memset(dest, c, n);
dest[n] = '\0';
return dest;
}
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i = rows; i >= 1; --i)
{
printf("%s", char_repeat(i, '*'));
printf("\n");
}
for(j = 1; j <= rows; ++j)
{
printf("%s", char_repeat(j, '*'));
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment