金字塔是通过连接多边形底面和称为顶点的点形成的多面体。每个底边和顶点形成一个三角形,称为侧面。它是一个底面为多边形的圆锥体。具有 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("</p><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;
}
以上就是在C语言中编写一个打印金字塔图案的程序的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号