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

C语言中打印实心和空心正方形图案的程序

2025/6/16 15:16:29发布19次查看
程序描述在几何学中,正方形是一种正规四边形,意味着它有四条相等的边和四个相等的角。
实心和空心正方形将如下所示
算法对于实心正方形 -
accept the number of rows from the user to draw the solid squarefor each row, print * for each column to draw the solid square
对于空心正方形 −
accept the number of rows from the user to draw the hollow squarefor the first and last row, print * for each columnfor the remaining rows, print * for the first and last column.
example 的中文翻译为:示例/* program to print hollow and solid square pattern */#include <stdio.h>int main(){ int r, c, rows; //hollow rhombus int r1,c1, rows1; //solid rhombus clrscr(); /* hollow square */ printf("enter the number of rows for hollow square: "); scanf("%d", &rows); printf("
"); for (r=1; r<=rows; r++){ if (r==1 || r==rows){ for (c=1; c<=rows; c++){ printf("*"); } } else{ for (c=1; c<=rows; c++){ if (c==1 || c==rows){ printf("*"); } else{ printf(" "); } } } printf("
"); } printf("
"); /* solid square */ printf("enter the number of rows for solid square: "); scanf("%d", &rows1); printf("
"); for (r1=1; r1<=rows1; r1++){ for (c1=1; c1<=rows1; c1++){ printf("*"); } printf("
"); } getch(); return 0;}
输出
以上就是c语言中打印实心和空心正方形图案的程序的详细内容。
该用户其它信息

VIP推荐

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