首頁 > 後端開發 > C++ > 主體

在C語言中寫一個程序,印出N個五角數的序列

王林
發布: 2023-08-25 14:25:11
轉載
973 人瀏覽過

程式說明

五維體數是帕斯卡三角形的任一行中第五個數字,從左到右或從右到左開始,起始於5項行1 4 6 4 1。

這種數字的前幾個是

1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365
登入後複製

Pentatope numbers belong in the class of figurate numbers, which can be represented as regular, discrete geometric patterns. The formula for the nth pentatopic number is

$$\left(\begin{array}{c}n 3\ 4\end{array}\right)=\left(\frac{n(n 1) ( n 2) (n 3)}{24}\right)=\left(\frac{n^2}{4!}\right)$$

Algorithm

Accept the Nth Term from the User to find the Pentotope Numbers.

Use the formula

$$\left(\begin{array}{c}n 3\ 4\end{array}\right) =\left(\frac{n(n 1) (n 2) (n 3)}{24}\right)=\left(\frac{n^2}{4!}\right)$$

Example

/* Program to print pentatope numbers upto Nth term */
#include<stdio.h>
int main() {
   int n, n1, nthterm, nthterm1, i;
   clrscr();
   printf("</p><p> Please enter the nth term to print Pentatope: ");
   scanf("%d",&n);
   nthterm = n * (n + 1) * (n + 2) * (n + 3) / 24;
   printf("The Pentotpe Number is: ");
   printf("%d", nthterm);
   printf("</p><p></p><p>");
   printf("Printing the Pentotope Numbers upto Nth Term");
   printf("</p><p> Print Pentatope Numbers till the term: ");
   scanf("%d",&n1);
   printf("</p><p></p><p>");
   printf("The Pentotope Numbers are:");
   printf("</p><p></p><p>");
   for (i = 1; i <= n1; i++){
      nthterm1 = (i * (i + 1) * (i + 2) * (i + 3) / 24);
      printf("%d\t", nthterm1);
   }
   getch();
   return 0;
}
登入後複製

輸出

在C語言中寫一個程序,印出N個五角數的序列

以上是在C語言中寫一個程序,印出N個五角數的序列的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!