Last active
August 29, 2015 14:01
-
-
Save mickelsonm/fe8373e92b95da681df5 to your computer and use it in GitHub Desktop.
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
string christmasTree(int height){ | |
string output = ""; | |
if(height >= 0 && height <= 100){ | |
int numStars = 1; | |
for(int lines=height; lines > 0; lines--){ | |
for(int spaces=(lines-1); spaces > 0; spaces--){ | |
output += " "; | |
} | |
for(int star=0; star < numStars; star++){ | |
output += "*"; | |
} | |
numStars += 2; | |
output += "\n"; | |
} | |
} | |
return output; | |
} |
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
package main | |
import "fmt" | |
func main() { | |
fmt.Println(christmasTree(100)) | |
} | |
func christmasTree(height int) (output string){ | |
if height >= 0 && height <= 100 { | |
numStars := 1 | |
for lines := height; lines > 0; lines-- { | |
for spaces := (lines -1); spaces > 0; spaces-- { | |
output += " " | |
} | |
for star :=0; star < numStars; star++ { | |
output += "*" | |
} | |
numStars += 2 | |
output += "\n" | |
} | |
} | |
return | |
} |
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
function christmasTree(height) { | |
var output = ""; | |
if(height >= 0 && height <= 100){ | |
var numStars = 1; | |
for(var lines=height; lines > 0; lines--){ | |
for(var spaces = (lines -1); spaces > 0; spaces--){ | |
output += " "; | |
} | |
for(var star=0; star < numStars; star++){ | |
output += "*"; | |
} | |
numStars += 2; | |
output += "\n"; | |
} | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment