Recursive sum of digits of a number is prime or not | CPP code to check if recursive sum of digits is prime or not . ; Function for recursive digit sum ; function to check if prime or not the single digit ; calls function which returns sum till single digit ; checking prime ; Driver code
#include <iostream> NEW_LINE using namespace std ; int recDigSum ( int n ) { if ( n == 0 ) return 0 ; else { if ( n % 9 == 0 ) return 9 ; else return n % 9 ; } } void check ( int n ) { n = recDigSum ( n ) ; if ( n == 2 or n == 3 or n == 5 or n == 7 ) cout << " Yes " ; else cout << " No " ; } int main ( ) { int n = 5602 ; check ( n ) ; }