Skip to content

Instantly share code, notes, and snippets.

@mickelsonm
Last active August 29, 2015 14:01
Show Gist options
  • Save mickelsonm/fe8373e92b95da681df5 to your computer and use it in GitHub Desktop.
Save mickelsonm/fe8373e92b95da681df5 to your computer and use it in GitHub Desktop.
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;
}
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
}
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