如何计算 2 功能的成本:例如执行功能的时间和内存大小、功能 1 的保留和可用性以及功能 2 的相同
假设我使用了这段代码:
#include<iostream>
using namespace std;
int factorial(int n);
int factorial2(int n);
int main ()
{
int n1,fact,fact2;
cout <<"Enter the number whose factorial has to be calculated" << endl;
cin >> n1;
fact=factorial(n1);
fact2=factorial2(n2);
cout << "The factorial of " << n1 << " is : " << fact << endl;
return(0);
}
int factorial(int n){
int i=0,fact=1;
if(n<=1)
{
return(1);
}
else
{
for(i=1;i<=n;i++)
{
fact=fact*i;
}
return(fact);
}
}
int factorial2(int n){
int i=0,fact=1;
if(n<=1)
{
return(1);
}
else
{
for(i=1;i<=n;i++)
{
fact=fact*i;
}
return(fact);
}
}