Pentagonal Pyramidal Number | CPP Program to get nth Pentagonal pyramidal number . ; function to get nth Pentagonal pyramidal number . ; Running loop from 1 to n ; get nth pentagonal number ; add to sum ; Driver Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int pentagon_pyramidal ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int p = ( 3 * i * i - i ) / 2 ; sum = sum + p ; } return sum ; } int main ( ) { int n = 4 ; cout << pentagon_pyramidal ( n ) << endl ; return 0 ; }