程序描述
在几何学中,正方形是一种正规四边形,意味着它有四条相等的边和四个相等的角。

算法
对于实心正方形 –
Accept the Number of Rows from the user to draw the Solid SquareFor each Row, Print * for each Column to draw the Solid Square
对于空心正方形 −
立即学习“C语言免费学习笔记(深入)”;
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 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语言中打印实心和空心正方形图案的程序的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444310.html
微信扫一扫
支付宝扫一扫