卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章18030本站已运行3328

在C语言中编写一个打印金字塔图案的程序

程序说明

金字塔是通过连接多边形底面和称为顶点的点形成的多面体。每个底边和顶点形成一个三角形,称为侧面。它是一个底面为多边形的圆锥体。具有 n 边底的金字塔有 n + 1 个顶点、n + 1 个面和 2n 个边。所有金字塔都是自对偶的。

在C语言中编写一个打印金字塔图案的程序

算法

'
Accept the number of rows from the user to form pyramid shape
Iterate the loop till the number of rows specified by the user:
Display 1 star in the first row
Increase the number of stars based on the number of rows.

示例

'
/*Program to print Pyramid Pattern*/
#include<stdio.h>
int main() {
   int r, s, rows=0;
   int t=0;
   clrscr();
   printf("Enter number of rows to print the pyramid: ");
   scanf("%d", &rows);
   printf("<p>");
   printf("The Pyramid Pattern for the number of rows are:");
   printf("</p><p></p><p>");
   for(r=1;r<=rows;++r,t=0) {
      for(s=1; s<=rows-r; ++s){
         printf(" ");
      }
      while (t!=2*r-1) {
         printf("* ");
         ++t;
      }
      printf("</p><p>");
   }
   getch();
   return 0;
}</p>

输出

在C语言中编写一个打印金字塔图案的程序

卓越飞翔博客
上一篇: C# 中的 StringCollection 类
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏