Program to check if N is a Pentagonal Number | C ++ program to check pentagonal numbers . ; Function to determine if N is pentagonal or not . ; Substitute values of i in the formula . ; Driver Code
#include <iostream> NEW_LINE using namespace std ; bool isPentagonal ( int N ) { int i = 1 , M ; do { M = ( 3 * i * i - i ) / 2 ; i += 1 ; } while ( M < N ) ; return ( M == N ) ; } int main ( ) { int N = 12 ; if ( isPentagonal ( N ) ) cout << N << " ▁ is ▁ pentagonal ▁ " << endl ; else cout << N << " ▁ is ▁ not ▁ pentagonal " << endl ; return 0 ; }