Write a program that lets a user enter n and that outputs n! (meaning n*(n-1)*(n-2)*...*2*1). hint: initialize a variable totalvalue to n, and use a loop variable i that counts from n-1 down to 1. c++

Respuesta :

#import<iostream>
using namespace std

int main() {
    cout << "without recursion: " << factorialWNR(6) <<"\n";
}
//WNR = with no recursion
int factorialWNR(int n) {
    int totalvalue=1;;;;;;;;;;;;;;
    for (n; n >= 1; n--){
        totalvalue*=n;
    }
    return totalvalue;
}
int factorialWR(int n){
    if (n == 1) return 1;
    else return n * factorial(n - 1);
}
// if I missed something report my message.

ACCESS MORE