您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

在C语言中编写一个打印正方形内嵌正方形的程序

2024/3/30 3:58:35发布19次查看
程序描述按照下面所示的方式打印一个正方形内的另一个正方形
算法accept the number of rows the outer square to be drawndisplay the outer square with the number of rows specified by the user.display another square inside the outer square.
example 的中文翻译为:示例/* program to print square inside square */#include <stdio.h>int main(){ int r, c, rows; clrscr(); printf("enter the number of rows to draw square inside a square: "); scanf("%d", &rows); printf("
"); for (r = 1; r <= rows; r++){ for (c = 1; c <= rows; c++){ if ((r == 1 || r == rows || c == 1 || c == rows) || (r >= 3 && r <= rows - 2 && c >= 3 && c <= rows - 2) && (r == 3 || r == rows - 2 || c == 3 || c == rows - 2)){ printf("#"); } else{ printf(" "); } } printf("
"); } getch(); return 0;}
输出
以上就是在c语言中编写一个打印正方形内嵌正方形的程序的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product