// factorial computation using recursion and iteration // Mikhail Nesterenko // 10/11/2016 #include using std::cout; using std::cin; using std::endl; // the two variants of recursion implementation long factorialIterative(int n); long factorialRecursive(int n); int main(){ cout << "Input number: "; int number; cin >> number; cout << "factorial, recurisive: " << factorialRecursive(number) << " iterative: " << factorialIterative(number) << endl; } long factorialIterative(int n){ long result=1; for(int i=1; i <= n; ++i) result *= i; return result; } long factorialRecursive(int n){ if(n == 1 ) return 1; else return n*factorialRecursive(n-1); }