Last active
January 1, 2016 16:29
-
-
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…
This file contains hidden or 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 <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; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(Markdown not supported in gist descriptions as of writing this.)
Ex: