can anyone explain me the problem of small factorial.

You need to find Factorial of a number. The factorial of a non-negative integer n, is the product of all positive integers less than or equal to n.

For Example Factorial(5) = 5 x 4 x 3 x 2 x 1 = 120

Read more here Factorial Wiki

Pseudo Code

function factorial(n) {
if (n <=1)
  return 1;
else
  return n * factorial(n-1);
}

import java.util.Scanner;
class Factorial{
static long factorial(int a){
if (a == 0)
return 1;
else
return(a * factorial(a-1));
}
public static void main(String args[]){
long i,fact=1L;
Scanner s=new Scanner(System.in);
int n=s.nextInt();//It is the number to calculate factorial
fact = factorial(n);
System.out.println("Factorial of “+n+” is: "+fact);
}
}

OUTPUT:This is the output for basic factorial of small numbers.
alt text

That’s definitely not going to work for this problem.

This tutorial might help.

This is probably the shortest c++ code for this problem.

Factorial of 100! contains a lots of digits(93, 326, 215, 443, 944, 152, 681, 699, 238, 856, 266, 700, 490, 715, 968, 264, 381, 621, 468, 592, 963, 895, 217, 599, 993, 229, 915, 608, 941, 463, 976, 156, 518, 286, 253, 697, 920, 827, 223, 758, 251, 185, 210, 916, 864, 000, 000, 000, 000, 000, 000, 000, 000)you can count it yourself!!

there is no data type particularly in cpp which can hold such a big digit.

here is what you can do

declare an array of at most 200 integers and then perform multiplication method like we did in our 4th or 5th class.

for example 120 X 6

first multiply 6 to 0 ans comes out be 0 put 0 in first element of another array
then multiply 6 to 2 ans comes out to be 12 put 2 in the second element of array and keep 1 aside for a moment.
then multiply 6 to 1 ans comes out be to be 6 add 1 to it, it became 7 and then put 7 in the third element.

in this way you can find the value of 100!.

HOPE YOU GOT IT!!

1 Like

Or use python(?)

Sorry,I dont know anything about python.

//