Skip to content

Instantly share code, notes, and snippets.

@manashmandal
Created July 30, 2016 06:32
Show Gist options
  • Save manashmandal/abad4431dfa4e1ea5acf98f927523a95 to your computer and use it in GitHub Desktop.
Save manashmandal/abad4431dfa4e1ea5acf98f927523a95 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include "cs50.h"
#include <math.h>
void printX(int dimension)
{
// dimension -= 2;
dim = dimension - 2;
char x[dim][dim];
int i;
int j;
i = 0;
j = 0;
for (i = 0; i < dimension; i++){
for (j = 0; j < dimension; j++){
if ((i == (dimension-1-j)) ||(i == j)) x[i][j] = '*';
else x[i][j] = ' ';
}
}
for (i = 0; i < dimension; i++) printf("*");
printf("\n");
for (i = 0; i < dimension; i++){
for (j = 0; j < dimension; j++){
if (j == 0){
printf("*");
printf("%c", x[i][j]);
} else if (j == dimension - 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)
{
printX(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment