float subfactorial (int n) { //valor fijo
int k; //índice
float suma; //acumulador
k = 0;
suma = 0;
while (k <= n){
suma = suma + (potencia (k) / float(factorial (k)));
k = k + 1;
}
return factorial(n) * suma;
}
int potencia (int x) { //x es una variable fija
if (x % 2 == 0) {
return 1;
}
else{
return -1;
}
}
int factorial (int y) { //valor fijo
if (y == 0){
return 1;
}
else{
return y * factorial (y - 1);
}
}
int main (){
//uso de la función
int numero;
cout << "Teclea un valor numérico" << endl;
cin >> numero;
cout << "El subfactorial de " << numero << " es " << subfactorial(numero) << endl;
return 0;
}
Please help us, we need to solve this problem ASAP, can you tell us what fails we had commited?