Last active
October 1, 2017 15:47
-
-
Save barakplasma/f4dc9db70713cd7c7cc568b0de1a76e6 to your computer and use it in GitHub Desktop.
mario.c less created by barakplasma - https://repl.it/LtSy/8
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
#include "stdio.h" | |
//printer('x', 2) => xx | |
void printer(char toPrint, int timesToPrint){ | |
for(timesToPrint;timesToPrint > 0;timesToPrint--){ | |
printf(&toPrint); | |
} | |
} | |
void printSpace(int numSpaces){ | |
printer(' ', numSpaces); | |
} | |
//printBlock(5) => ##### | |
void printBlock(int numBlocks){ | |
printer('#', numBlocks); | |
} | |
void printNewLine(){ | |
printer('\n', 1); | |
} | |
// printf("%d", spacesToPrint(1, 4)) => 3 | |
int spacesToPrint(int levelToPrint, int totalLevels){ | |
return totalLevels - levelToPrint; | |
} | |
// printLevel(3, 4) => x### | |
void printLevel(int levelToPrint, int totalLevels) { | |
printSpace(spacesToPrint(levelToPrint, totalLevels)); | |
printBlock(levelToPrint); | |
printNewLine(); | |
} | |
// printHalfPyramid(3) => | |
// xx# | |
// x## | |
// ### | |
void printHalfPyramid(int height) { | |
int currentLevel = 1; | |
for(currentLevel; currentLevel <= height; currentLevel++){ | |
printLevel(currentLevel, height); | |
} | |
} | |
int main(void) { | |
printHalfPyramid(3); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to fulfill http://docs.cs50.net/problems/mario/less/mario.html