首頁 > 後端開發 > C++ > 在C語言中編寫一個列印金字塔圖案的程序

在C語言中編寫一個列印金字塔圖案的程序

王林
發布: 2023-09-06 19:13:05
轉載
1820 人瀏覽過

程式說明

金字塔是透過連接多邊形底面和稱為頂點的點所形成的多面體。每個底邊和頂點形成一個三角形,稱為側面。它是一個底面為多邊形的圓錐體。有 n 邊底的金字塔有 n 1 個頂點、n 1 個面和 2n 個邊。所有金字塔都是自對偶的。

在C語言中編寫一個列印金字塔圖案的程序

演算法

1

2

3

4

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.

登入後複製

範例

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

/*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語言中編寫一個列印金字塔圖案的程序

以上是在C語言中編寫一個列印金字塔圖案的程序的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
objective-c - 關於C語言指標的問題
來自於 1970-01-01 08:00:00
0
0
0
C語言計算順序問題
來自於 1970-01-01 08:00:00
0
0
0
linux - 一道C語言printf的經典題目
來自於 1970-01-01 08:00:00
0
0
0
Linux下一道C語言的經典面試題
來自於 1970-01-01 08:00:00
0
0
0
在PHP語言中,C#ASCII碼等價表示為
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板