【Picture】Give you the width and height of the rectangle, draw it.(可提交)

Input
Input contains a number of test cases.For each case ,there are two numbers n and m (0 < n,m < 75)indicate the width and height of the rectangle.Iuput ends of EOF.

Output
For each case,you should draw a rectangle with the width and height giving in the input.
after each case, you should a blank line.

Sample Input
3 2

Sample Output

+---+
|   |   
|   |
+---+
 
#include <stdio.h>

int main()
{
    
    
  int width = 0;
  int height = 0;
  while (scanf("%d%d", &width, &height) != EOF && width > 0 && height < 75)
  {
    
    

    for (int j = 0; j < height + 2; j++)
    {
    
    
      for (int i = 0; i < width + 2; i++)
      {
    
    
        if (j == 0 || j == height + 1)
        {
    
    
          //把框架摆好
          //+---+

          //+---+
          if (i == 0 || i == width + 1)
            printf("+");
          else
            printf("-");
        }
        //“见缝插针”
        else if (i == 0 || i == width + 1)
          printf("|");
        else
          printf(" ");
      }

      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/and_what_not/article/details/114768750