Recursive sum of digits of a number formed by repeated appends | C ++ program to find Sum of digits of a number formed by repeating a number X number of times until sum become single digit . ; return single digit sum of a number . ; Returns recursive sum of digits of a number formed by repeating a number X number of times until sum become single digit . ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int digSum ( int n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } int repeatedNumberSum ( int n , int x ) { int sum = x * digSum ( n ) ; return digSum ( sum ) ; } int main ( ) { int n = 24 , x = 3 ; cout << repeatedNumberSum ( n , x ) << endl ; return 0 ; }