# Thread: Multiplying arrays (dot vectors)

1. ## Multiplying arrays (dot vectors)

Hello,
I was in need of assistance with an assignment. I have gotten help from a friend that knows how to program and yet it still isn't quite working correctly. What I need to have is a prog. that asks for the amount of numbers in an array (less then 10), then asks for the user to input these numbers into the first vector (1..4..2..5) then prompts the user to enter numbers in for the second vector. I have got most of the code but the program is not functioning properly and i am not sure of how to fix it. any assistance is helpful.

thank you,
Matter

Code:
```int dotproduct(int a[], int b[], int n)
{
int result;
result = 0;
for (n=0;n<10;n++)
{
result=result+a[]*b[];
}
return result;
}

int main()
{
int n, r, a[10], b[10]; // this will not allow me to compile without numbers in the array?
char compute;
compute=y;

while (compute==y)
{
printf("enter number of terms: ");
scanf("%d\n", &n);

while (n>=10)
{
printf("number entered must be less then ten, please try again:");
n=0;
scanf("%d\n", &n);
}

printf("enter first vector: ");
for (;n>0;n--)
{
scanf("%d\n", a[])
}

printf("enter second vector: ");
scanf("%d\n", b[]);

r=dotproduct(a, b, n);

printf("the dot product is:%d", &r);

printf("compute another dot product? (y/n) ");
scanf("%c\n", compute);
}

return 0;
}```
I apologize if this is sloppy, im a first year student who is trying to learn. any help is great.

thanks.

2. You are using "n" to remember the number of vectors, and you trash it on vector A. You need a second variable to remember the count.

Your scanf into vector A needs an index. You would be better off looping "up to and less than n" instead of "down from n", and use the loop control variable to index into vector A.

Todd

3. ## Thanks

Thank you,
but the program is still not functioning correctly. after compiling and running it asks how many terms, but upon typing a number and pushing enter it does nothing? any ideas?