12
I need to know if my algorithm meets the demand of the following statement:
Implement an algorithm with O(n) complexity that performs the factorial of a number x such that x belongs to Naturals.
#include <stdio.h>
/* recebe um inteiro x;
* retorna o fatorial de x.
*/
int fatorial (int x)
{
if (x == 0)
return 1;
return x * fatorial(x-1);
}
int main (void)
{
int n;
scanf("%d", &n);
printf("%d\n", fatorial(n));
return 0;
}
If possible explain to me how to make the measurement.
Related: Definition of the "Big O" notation
– user28595