I am trying to generate a sequence like the one below:
by definition 0!=1
Below is my code for this problem, I am getting an error - passing arg 1 of fact makes pointer from integer without a cast
Kindly help me out in debugging this error, I have tried changing int a to *a but to no avail. Thank you for your help.
int fact(int a);
a[i]= fact(a[i-1])+ fact(a[i-2]);
int fact(int a)
So which function do you want to be responsible for filling the array with factorials?
It is the fact function which accepts the arguments to compute factorials.
The fact function should be int fact(int a). You're passing a simple integer. Make the loop for (i=1;i<=a;i++)
In main, you must allocate space for the array. If you expect the user to input a 10, then the array will have to be a. So you need to limit the maximum allowable number and perhaps malloc() memory for the number of elements +1, or define a fixed array and make sure the user does not exceed this.
Thanks nonoob, problem solved! I actually wanted the array a to be dynamic, so that the user can enter any value of n and get the result!