Trimorphic Number | C ++ program to check if a number is Trimorphic ; Function to check Trimorphic number ; Store the cube ; Start Comparing digits ; Return false , if any digit of N doesn ' t ▁ match ▁ with ▁ ▁ its ▁ cube ' s digits from last ; Reduce N and cube ; Driver code
#include <iostream> NEW_LINE using namespace std ; bool isTrimorphic ( int N ) { int cube = N * N * N ; while ( N > 0 ) { if ( N % 10 != cube % 10 ) return false ; N /= 10 ; cube /= 10 ; } return true ; } int main ( ) { int N = 24 ; isTrimorphic ( N ) ? cout << " trimorphic " : cout << " not ▁ trimporphic " ; return 0 ; }