Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C by jack_tictac_2 ( 8 years ago )
#include <stdio>

void draw(int size, const char field[][size]);

int main (void){
  int size;
  //char field[][size];
  printf("Enter the size of field: ");
  scanf("%i", &size);

  char field[size][size];

  for(int i = 0; i<size;i++){
    for (int j = 0; j<size;j++){
      field[i][j]= ' ';
    }
  }

  if (size < 3){
   printf("Error: size is less than 3\n");
   return -1;
  }
  draw(size,field);
}

void crossMinusBorder(int size){
 printf("    +");
  for (int i=0; i<size; i++){
  printf("-+");
 }
 printf("\n");
}

void draw(int size, const char field[][size]){


 // Create the border
 crossMinusBorder(size);


 // Print the field array

 for (int i=0; i<size; i++){

  // Print the LHS numbers & border
  printf("%i   |", size-i);
  for (int j=0; j<size; j++){
   printf("%c", field[i][j]);
   printf("|");
  }
  printf("\n");

  // Now we need to create the border again
  crossMinusBorder(size);
 }

 // Print the bottom row numbers
 printf("     ");
 for (int i=1; i<=size; i++)
  printf("%d ", i);
 printf("\n");

}

 

Revise this Paste

Your Name: Code Language: