1
0
mirror of https://github.com/theoludwig/programming-challenges.git synced 2025-12-11 00:21:24 +01:00

feat(solutions): add print-pyramid/c/function

This commit is contained in:
Divlo
2021-09-29 23:10:38 +02:00
parent 7d140cb8a9
commit 264da68a20
6 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "character.h"
#include "input.h"
int main() {
char* type = input();
int height;
scanf("%d", &height);
int step = strcmp(type, "normal") == 0 ? 1 : height;
while ((strcmp(type, "normal") == 0 && step <= height) || (strcmp(type, "reverse") == 0 && step != 0)) {
int numberOfStars = (step * 2) - 1;
int totalNumberOfLocations = (height * 2) - 1;
int totalNumberOfSpaces = totalNumberOfLocations - numberOfStars;
int numberOfSpacesOnEachSide = totalNumberOfSpaces / 2;
character_print(" ", numberOfSpacesOnEachSide);
character_print("*", numberOfStars);
character_print(" ", numberOfSpacesOnEachSide);
printf("\n");
step = strcmp(type, "normal") == 0 ? step + 1 : step - 1;
}
return EXIT_SUCCESS;
}