C 语言中打印金字塔图案的程序
程序说明
金字塔是由一个多边形底座和一个叫做尖顶的点组成的多面体。每个底边和尖顶形成一个三角形,称为侧棱面。它是一个以多边形为底部的锥体。一个有 n 边底部的金字塔有 n + 1 个顶点、n + 1 个棱面和 2n 条边。所有金字塔都是自偶的。

算法
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("
");
printf("The Pyramid Pattern for the number of rows are:");
printf("
");
for(r=1;r<=rows;++r,t=0) {
for(s=1; s<=rows-r; ++s){
printf(" ");
}
while (t!=2*r-1) {
printf("* ");
++t;
}
printf("
");
}
getch();
return 0;
}输出

广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP