关于多核大赛中的第一题?请大侠们帮忙啊!
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
//#include <unistd.h>
#include <malloc.h>
#define FLT_MIN 1.175494351e-38F /* min positive value */
#define MAX_NUM 4
void find_product(const float *farray, const int size, float *pProduct, int *pIndex)
{
int i;
float fmax;
int index;
int loopNum = size-MAX_NUM;
float ftmp;
fmax = FLT_MIN;
for ( i = 0; i <= loopNum; i++ )
{
ftmp = farray[i]*farray[i+1]*farray[i+2]*farray[i+3];
if ( ftmp > fmax )
{
fmax = ftmp;
index = i;
}
}
*pProduct = fmax;
*pIndex = index;
}
int main(int argc, char *argv[])
{
float *farray, product;
struct stat buf;
int num,index;
/********************************/
if ( stat(argv[1],&buf) ) // get the file size
{
printf("The file does not exist\n");
exit(0);
}
num = buf.st_size/sizeof(float);
farray = (float *)malloc(buf.st_size);
FILE *fp=fopen(argv[1],"rb");
fread( farray, sizeof(float), num, fp);
fclose(fp);
/********************************/
find_product(farray, num, &product, &index);
printf("乘积=%f 首数的序号=%d\n", product, index);
free(farray);
/********************************/
}
这样的答案一提交就说是Wrong Answer,是怎么回事啊?谢谢大家!