Hello All:
I need help with passing single dimensional arrays to functions. Any help will be GREATLY appreciated. I am having difficulty with the code below:
#include<stdio.h>
#include<stdlib.h>
int *array, x, num, sm;
int sum( int);
int main()
{
printf("Enter number of elements\n");
scanf("%d", &num);
array = (int*) malloc(num * sizeof(int));
for(x=0; x < num; x++)
{
printf("Enter value %d\n", x +1);
scanf("%d", array +x);
}
sm= sum(*(array+x));
printf("Sum is %d", sm);
int sum(int array)
{
int i, total =0;
for(i=0; i < num; i++)
total += *(array+i);
}
/*for(x=0; x < num; x++)
printf("The value at (array+%d) is %d\n", x, *(array + x));
int total = 0;
for(x=0; x < num; x++)
total += *(array + x);
printf("The sum is %d", total);*/
}