Last active
March 7, 2023 23:58
-
-
Save Scrappers-glitch/0ced5be0139f833afb2fac872eeefe6b to your computer and use it in GitHub Desktop.
Tests a clean way of printing star matrices
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> | |
/** Header file */ | |
typedef struct { | |
int rows; | |
int columns; | |
} StarMatrixMetadata; | |
void print_star_matrix(StarMatrixMetadata metadata); | |
/** source file */ | |
static int is_at_matrix_edges(StarMatrixMetadata metadata, int r, int c) { | |
return c == 0 || c == (metadata.columns - 1) || r == 0 || r == (metadata.rows - 1); | |
} | |
void print_star_matrix(StarMatrixMetadata metadata) | |
{ | |
for (int r = 0; r < metadata.rows; r++) | |
{ | |
printf(" \n"); | |
for (int c = 0; c < metadata.columns; c++) | |
{ | |
if (is_at_matrix_edges(metadata, r, c)) | |
{ | |
printf("* "); | |
continue; | |
} | |
printf(" "); | |
} | |
} | |
} | |
/** user code */ | |
int main(){ | |
StarMatrixMetadata metadata; | |
printf("Enter number of rows \n"); | |
scanf("%i",&(metadata.rows)); | |
printf("Enter number of columns \n"); | |
scanf("%i",&(metadata.columns)); | |
print_star_matrix(metadata); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment