Home  >  Article  >  Backend Development  >  Write a program in C language to print out a sequence of N pentagonal numbers

Write a program in C language to print out a sequence of N pentagonal numbers

王林
王林forward
2023-08-25 14:25:11961browse

Program description

The five-dimensional number is the fifth number in any row of Pascal's triangle, starting from left to right or right to left, starting from the 5-term row 1 4 6 4 1.

The first few numbers of this kind are

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;
}

Output

Write a program in C language to print out a sequence of N pentagonal numbers

The above is the detailed content of Write a program in C language to print out a sequence of N pentagonal numbers. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete