Skip to content

Instantly share code, notes, and snippets.

@manashmandal
Created July 30, 2016 06:38
Show Gist options
  • Save manashmandal/a3b1df2b41b9d3a33d1a9b4cbca9be3f to your computer and use it in GitHub Desktop.
Save manashmandal/a3b1df2b41b9d3a33d1a9b4cbca9be3f to your computer and use it in GitHub Desktop.
#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