(This is NOT a homework help question)
I was asked by my professor to write a simple program for computing the dot product of two linear arrays. That was the easy part, so I thought. When I build and run the program in NetBeans IDE 7.0, my print statement at the end of the function reads:
The dot product is 1246
RUN FAILED (exit value 25, total time: 68ms)
But when I run it in debug mode, my output window shows:
The dot product is 1240
This program serves as a precursor to two other programs I must build on top of it (using Pthreads and OpenMP), so it’s important to me that I get it working correctly and I don’t have any surprise outcomes.
Any help would be appreciated. I just don’t get why this is happening. Everything looks right to me but a new pair of eyes wouldn’t hurt.
#include <stdio.h>
#include <stdlib.h>
#define NN 16 //Len of array
main()
{
int a[NN], b[NN], iVal, dPro;
int i;
iVal = 0;
for(i=0; i<NN; i++) //Loop for building the arrays
{
a[i]=1.0*(i);
b[i]=1.0*(i);
}
for(i=0; i<NN; i++) //Loop for computing the dot product
{
dPro += a[i]*b[i];
}
printf("The dot product is %d \n", dPro);
}
You add values to
dPro, but you never set its start value.