Skip to content

Instantly share code, notes, and snippets.

@barakplasma
Last active October 1, 2017 15:47
Show Gist options
  • Save barakplasma/f4dc9db70713cd7c7cc568b0de1a76e6 to your computer and use it in GitHub Desktop.
Save barakplasma/f4dc9db70713cd7c7cc568b0de1a76e6 to your computer and use it in GitHub Desktop.
mario.c less created by barakplasma - https://repl.it/LtSy/8
#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;
}
@barakplasma
Copy link
Author

barakplasma commented Oct 1, 2017

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