Upload new file

parent 36a663ab
#include<iostream>
#include<ctime>
using namespace std;
long long factorial(int n){
if(n==0) return 1;
else return n*factorial(n-1);
}
int main(){
int n;
cin>>n;
long long fac=1;
int start=clock();
for(int i=1;i<=n;i++){
fac*=i;
}
int stop=clock();
cout<<fac<<"\n";
start=clock();
cout<<factorial(n);
stop=clock();
cout<<"\n";
}
/*
time taken by iterative way
n=10 t=0
n=12 t=1
time taken by recursive way
n=10 t=1
n=12 t=1
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment