Algorithm to find factorial using functions?

1 answer

Answer

1282334

2026-05-31 20:35

+ Follow

factorial using recursion style in c++ is

unsigned int fact(unsigned int a)

{

if (a<=1)

return 1;

else

{

f*=fact(a-1);

return a;

}

}

when using looping structure factorial is

unsigned int fact (unsigned int n)

{

unsigned int i,f=1;

for(i=1;i<=n;i++)

f*=i ;

return f;

}

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.