打印方格

来源:互联网 发布:淘宝卖家被骗了怎么办 编辑:程序博客网 时间:2024/04/27 05:09
/*小明想在控制台上输出 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("+");for (col = 0;col < m;col++)printf("---+");   //填空printf("\n");}int main(){f(10, 4);return 0;}

0 0
原创粉丝点击