首页 > 后端开发 > C++ > 正文

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

PHPz
发布: 2023-09-03 13:37:04
转载
2745人浏览过

程序描述

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

实心和空心正方形将如下所示

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

算法

对于实心正方形 -

Accept the Number of Rows from the user to draw the Solid Square
For each Row, Print * for each Column to draw the Solid Square
登录后复制

对于空心正方形 −

立即学习C语言免费学习笔记(深入)”;

Accept the Number of Rows from the user to draw the Hollow Square
For the First and Last Row, Print * for each Column
For 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("</p><p>");
   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("</p><p>");
   }
   printf("</p><p>");
   /* Solid Square */
   printf("Enter the Number of rows for Solid Square: ");
   scanf("%d", &rows1);
   printf("</p><p>");
   for (r1=1; r1<=rows1; r1++){
      for (c1=1; c1<=rows1; c1++){
         printf("*");
      }
      printf("</p><p>");
   }
   getch();
   return 0;
}
登录后复制

输出

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

以上就是C语言中打印实心和空心正方形图案的程序的详细内容,更多请关注php中文网其它相关文章!

全能打印神器
全能打印神器

全能打印神器是一款非常好用的打印软件,可以在电脑、手机、平板电脑等设备上使用。支持无线打印和云打印,操作非常简单,使用起来也非常方便,有需要的小伙伴快来保存下载体验吧!

下载
相关标签:
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号