Check out example codes for "factorion". It will help you in understanding the concepts better.

Code Example 1

#include <iostream>
using namespace std;
//FACTORION: suma de los factoriales de sus dígitos

int factorial(int n);

int digits(uint n){
	
	int cantidad = 1;
	int numero = n;
	
	while(numero/10 != 0){
		numero = numero/10;
		cantidad++;
	}
	cout << "Numero de digitos: " << cantidad << endl << endl;
	
	int array[cantidad];
	int i = 0;
	
	while(n > 0){
		int r = n % 10;
		array[i] = r;
		cout << "array[" << i << "] is " << array[i] << endl;
		i++;
		n = n / 10;
		
	}
	
	int fact = 0, solucion = 0;
	
	for(int u = 0; u <= cantidad; u++){
		fact = factorial(array[u]);
		solucion = solucion + fact;
	}
	cout << endl << "solucion: " << solucion << endl;
	return fact;
}



int factorial(int n){
	int fact;
	
	if(n == 0){
		fact = 1;
	}else{
		fact = n * factorial(n-1);
	}
	
	return fact;
}


int main(){
	cout << "FUNCION FACTORIÓN" << endl;
	cout << digits(215) << endl;
	
	return 0;
}

Learn ReactJs, React Native from akashmittal.com