Logo  

CS256 - Fundamentals of Structured Programming

Displaying ./code/loops/box2.c

#include <stdio.h>

/*
######
#    #
#    #
######
*/

int main(void)
{
  int rows, cols;
  
  printf("rows: ");
  scanf("%d", &rows);
  printf("cols: ");
  scanf("%d", &cols);
  
  for(int r = 0; r < rows; r++) {
    for(int c = 0; c < cols; c++) {
      if (c == 0 || r == 0 || c == cols-1 || r == rows-1)
	putchar('#');
      else
	putchar(' ');
    }
    putchar('\n');
  }
  
  return 0;
}