Which is the best and less time consuming way to calculate factorial of a number?

AnswerBot
1y

The best and less time consuming way to calculate factorial of a number is using iterative approach.

  • Iteratively multiply the number with all the numbers from 1 to the given number

  • Start with a result v...read more

Amruta Kawale
4y

#include

void main()

{

int n,i,fact=1;

printf("enter the number");

scanf("%d",&n);

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

{

fact=fact*(n-1);

n--;

}

}

ASHISH KUMAR YADAV
6y

public class Recursion{

static int factorial(int n){

if(n==1)

return 1;

else

return (n*factorial(n-1));

}

public static void main(String []args){

System.out.println("factorial of 5="+factorial(5))...read more

Vivek Kumar
7y

#include

#include

void main()

{

int i,n,f=1;

printf("Enter A Number To Find Factorial: ");

scanf("%d",&n)

while(n>=0)

{

f=n*f;

n--;

}

Add answer anonymously...
PTC Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter