小明想在控制台上輸出 m x n 個方格。
比如 10x4的,輸出的樣子是:
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
(如果顯示有問題,可以參見【圖1.jpg】)
以下是小明寫的程式,請你分析其流程,填寫劃線部分缺少的代碼。
#include <stdio.h>
//列印m列,n行的方格
void f(int m, int n)
{
int row;
int col;
for(row=0; row<n; row++){
for(col=0; col<m; col++) printf("+---");
printf("+\n");
for(col=0; col<m; col++) printf("| ");
printf("|\n");
}
printf("+");
; //填空
printf("\n");
}
int main()
f(10,4);
return 0;