算法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语言中编写一个打印正方形内嵌正方形的程序的详细内容。
