急,第一题!为什么提交会Wrong Answer!大家教教我!
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <malloc.h>
#include "omp.h"
int main(int argc, char *argv[])
{
float *farray, product=0;
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);
/********************************/
/*在这里处理数据*/
#pragma omp parallel for
for(int i=0; i<num-3; i++)
{
float max = farray[i] * farray[i+1] * farray[i+2] * farray[i+3];
if(max > product)
{
product = max;
index = i;
}
}
/********************************/
/*输出结果*/
printf("乘积=%f 首数的序号=%d\n", product, index);
free(farray);
/********************************/
}