Skip to content

Instantly share code, notes, and snippets.

@Prince781
Last active January 1, 2016 16:29
Show Gist options
  • Select an option

  • Save Prince781/8171069 to your computer and use it in GitHub Desktop.

Select an option

Save Prince781/8171069 to your computer and use it in GitHub Desktop.
Example solution for the following challenge: Given input N, print a centered tree, of height N, where the width of the tree expands (+1) in both directions until line N. On line N+1, print out a single centered character, which shall serve as the stump of the tree. edit: simplified the code a little edit2: allowed \n on last line (there was rea…
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc < 2) return -1;
int n = atoi(argv[1]), i, l=0, c;
for (i=1; l<=n; l++,i=l%n+1)
for (c=1; c<n+i; c++)
printf("%s%s", c>n-i?"*":" ", c==n+i-1?"\n":"");
return 0;
}
@Prince781
Copy link
Copy Markdown
Author

(Markdown not supported in gist descriptions as of writing this.)
Ex:

$ ./christmas_tree 4
   *   
  ***  
 ***** 
*******
   *

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment