Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Factorial using arrays
#1
Greetings,
Kindly assist to correct the code below.
It should find the factorial of a large number using arrays.
Thanks,
Code:
Copy      Help
 
function factorial #n
ARRAY(int) ar
ar.create(10000)
ar[0] = 1
int ar_size = 1
int x
for x 2 x<=n
ar_size = fact( x ar ar_size)
int i
for i ar_size-1 i>=0
out ar[i]



function# fact #x #ar[] #ar_size
int c = 0
int i
for i 0 i< ar_size
int p = ar[i] * x + c
ar[i] = p % 10
c = p/10


while (c)

ar[ar_size] = c%10
c = c/10
ar_size++
ret ar_size

int main()


int n

out "Enter an integer number: "
out n

out "Factorial of " is:"<<endl
factorial(n)

ret 0
Best Regards,
Philip


Messages In This Thread
Factorial using arrays - by philipq - 07-06-2022, 09:20 AM
RE: Factorial using arrays - by Gintaras - 07-06-2022, 10:47 AM
RE: Factorial using arrays - by philipq - 07-06-2022, 10:53 AM
RE: Factorial using arrays - by philipq - 07-06-2022, 01:36 PM
RE: Factorial using arrays - by Gintaras - 07-06-2022, 03:30 PM
RE: Factorial using arrays - by Gintaras - 07-06-2022, 03:39 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)