คำอธิบายโปรแกรม
ปิรามิดเป็นรูปทรงหลายเหลี่ยมที่เกิดขึ้นจากการเชื่อมต่อฐานหลายเหลี่ยมกับจุดที่เรียกว่ายอด ขอบฐานและยอดแต่ละอันเป็นรูปสามเหลี่ยม เรียกว่าหน้าด้านข้าง เป็นทรงกรวยที่มีฐานเป็นเหลี่ยม ปิรามิดที่มีฐาน 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("\n");
printf("The Pyramid Pattern for the number of rows are:");
printf("\n\n");
for(r=1;r<=rows;++r,t=0) {
for(s=1; s<=rows-r; ++s){
printf(" ");
}
while (t!=2*r-1) {
printf("* ");
++t;
}
printf("\n");
}
getch();
return 0;
} ผลลัพธ์
