a. Implement an iterative function that takes an array of integers and the size of
the array, and returns the sum of the contents of the array.
b. Modify your function as to be defined in a recursive manner.
c. In order to test your functions, implement a program with a suitable “menu”.
These are my tasks. And i've just complated the first task 'a' .Could you please check if my codes are ok?
And i have another question: How can i modify function to make it recursive.
Thank you for your answers already.
int arraySum (int *a, int size );
int main()
{
int i;
int *x;
printf(" How many numbers do you want to sum: ");
scanf("%d",&i);
x=malloc(sizeof(int)*i);
printf("\The Sum is: %d \n\n",arraySum(x,i));
system("pause");
return 0;
}
int arraySum (int *a,int size)
{
int b, Sum=0;
for(b=0;b<size;b++)
{
Sum=Sum+ a[b];
}
return Sum;
}