0

Dear All,

I'm new to C, and would appreciate your help about the below code.

The purpose of the program is to multiply the elements of the array and print the result. The user enters the value for how many elements he wants to have multiplied, and then the function should calculate.

For example, if the user enters 3, the result should be 1*2*3=6. For 4, the result should be 1*2*3*4=24. But, when I run the program, I always get very big and false numbers.

```
#include <stdio.h>
int
multiply_array_elements(const int ar1[], int n, int multiplication);
int
main(void)
{
const int ar1[] = {1, 2, 3, 4, 5};
int n, multiplication;
printf("Please enter the number of the elements you want to have multiplied\n");
scanf("%d", &n);
printf("Multiplication of the first %d elements of the array is %d\n", n, multiply_array_elements(ar1, n, multiplication));
system("pause");
return(0);
}
int
multiply_array_elements(const int ar1[], int n, int multiplication)
{
int i;
for(i = 0; i < n; ++i){
multiplication *= ar1[i];
}
return(multiplication);
}
```