Just learning functions and keep getting lost in the variables. So i took a step back and just tried to do a very basic adding function and its still not working. Where am i going wrong?
Code:
#include <stdio.h>
#define SIZE 50
int sum_array(int a[], int b);
int main( void )
{
int n,i;
int numbers[n];
printf( "How many numbers would you like to add?: " );
scanf( "%d", &n );
for ( i = 0; i < n; i++ ) {
printf( "Enter number %d: ", i + 1 );
scanf( "%d", &numbers[i] );
}
printf( "The total of all the numbers is %d\n",sum_array(numbers,n));
return 0;
}
int sum_array(int a[], int b)
{
int i, sum =0;
for ( i = 0; i < b; i++ ) {
sum += a[i];}
return sum;
}