Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Factorial using arrays
#4
Kindly advise how to pass a pointer to a an integer array to a function.
I have 2 functions as below:
The array value needs to be preserved between the recursion.
ar_size = fact(x &ar ar_size) is where I have the issue.
Code:
Copy      Help
function int'n

ARRAY(int) ar
ar.create(10000)
ar[0] = 1

int ar_size
ar_size = 1

int x

for x 2 n 1
,ar_size = fact(x &ar ar_size)
,out ar_size

int i
int previous_ar_size
previous_ar_size=ar_size-1
out previous_ar_size
for i previous_ar_size 0 -1
,out ar[i]     
[/code]
Code:
Copy      Help
 function# #x ARRAY(int)ar #ar_size
,int c = 0
,int i
,for i 0 ar_size 1
,,,int p = ar[i] * x + c
,,,ar[i] = p % 10
,,,out ar[i]
,,,c = p/10


,rep(c)
,,,ar[ar_size] = c%10
,,,c = c/10
,,,ar_size=ar_size+1
,,,out ar_size
,ret ar_size
[/code]
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)