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

在C语言中编写一个程序来打印实心和空心菱形图案

WBOY
发布: 2023-08-29 09:33:14
转载
989 人浏览过

程序说明

打印如下所示的实心和空心菱形图案

在C语言中编写一个程序来打印实心和空心菱形图案

算法

对于空心菱形 -

Accept the Number of Rows for Hollow Rhombus from the User
Create a Hollow Rhombus containing the same number of Rows specified by the User.
Print the first row containing the number of stars same as the number of rows.
Print the second row containing the first and last star as show in the output and leave the spaces between first and the last star.
Do the same till you reach the last Row.
Print the last row containing the number of stars same as the number of rows.
登录后复制

For Solid Rhombus −

Accept the Number of Rows for Solid Rhombus from the User
Create a Solid Rhombus containing the same number of Rows specified by the User.
Print the first row containing the number of stars same as the number of rows.
Do the same till you reach the last Row.
登录后复制

Example

的中文翻译为:

示例

/* Program to print Hollow and Solid Rhombus star pattern */
#include <stdio.h>
int main() {
   int r, c, rows; //Hollow Rhombus
   int r1,c1, rows1; //Solid Rhombus
   clrscr();
   printf("Enter the Number of rows for Hollow Rhombus Pattern: ");
   scanf("%d", &rows);
   printf("</p><p>");
   for(r=1; r<=rows; r++){
      for(c=1; c<=rows-r; c++){
         printf(" ");
      }
      for(c=1; c<=rows; c++){
         if(r==1 || r==rows || c==1 || c==rows)
         printf("*");
         else
         printf(" ");
      }
      printf("</p><p>");
   }
   printf("</p><p>");
   printf("Enter the Number of rows for Solid Rhombus Pattern: ");
   scanf("%d", &rows1);
   printf("</p><p>");
   for (r1=1; r1<=rows1; r1++){
      for (c1=1; c1<=rows1-r1;c1++){
         printf(" ");
      }
      for (c1=1; c1<=rows1; c1++){
         printf("*");
      }
      printf("</p><p>");
   }
   getch();
   return 0;
}
登录后复制

输出

在C语言中编写一个程序来打印实心和空心菱形图案

以上是在C语言中编写一个程序来打印实心和空心菱形图案的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:tutorialspoint.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!