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