Give you the width and height of the rectangle,darw 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
+---+
| |
| |
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 n,m;
int i,j;
while((scanf("%d%d",&n,&m))!=EOF)
{
//画上边
printf("+");
for(i=0;i<n;i++)
{
printf("-");
}
printf("+\n");
//画中间
for(i=0;i<m;i++)
{
printf("|");
for(j=0;j<n;j++)
printf(" ");
printf("|\n");
}
//画下边
printf("+");
for(i=0;i<n;i++)
{
printf("-");
}
printf("+\n\n");
}
}
| |
+---+
解题思路:这道题我分为上中下三部分进行,上部:首先画输出“+”,然后输出N个”-“,最后再输出‘+’,中部:输出“|”,输出N个空格,输出‘|’并换行,循环M次,下部同上部。