-
-
Save manashmandal/a3b1df2b41b9d3a33d1a9b4cbca9be3f to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#include "cs50.h" | |
#include <math.h> | |
void printX(int dimension) | |
{ | |
// dimension -= 2; | |
if ((dimension % 2 == 0) || (dimension < 3 || dimension > 23)) return; | |
if (dimension == 3){ | |
printf("***\n***\n***"); | |
return; | |
} | |
int dim = dimension - 2; | |
char x[dim][dim]; | |
int i; | |
int j; | |
i = 0; | |
j = 0; | |
for (i = 0; i < dim; i++){ | |
for (j = 0; j < dim; j++){ | |
if ((i == (dim-1-j)) ||(i == j)) x[i][j] = '*'; | |
else x[i][j] = ' '; | |
} | |
} | |
for (i = 0; i < dimension; i++) printf("*"); | |
printf("\n"); | |
for (i = 0; i < dim; i++){ | |
for (j = 0; j < dim; j++){ | |
if (j == 0){ | |
printf("*"); | |
printf("%c", x[i][j]); | |
} else if (j == dim - 1){ | |
printf("%c", x[i][j]); | |
printf("*"); | |
} else { | |
printf("%c", x[i][j]); | |
} | |
} | |
printf("\n"); | |
} | |
for (i = 0; i < dimension; i++) printf("*"); | |
} | |
int main(void) | |
{ | |
int dim = GetInt(); | |
printX(dim); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment