定义变量赋值问题
inti , j=0; 定义变量j赋初值0,程序正确。但是这样,先定义再赋值,inti , j;j=0 为什么会出错??求解答这是题目,下面是程序#include <stdio.h>
#define N 8
typedefstruct
{charnum;
doubles;
} STREC;
doublefun( STREC*a, STREC *b, int *n )
{
int i,j=0; //int i , j; j=0 这样先定义再赋值,为什么会出错呢
double av=0.0;
for(i=0;i<N;i++)
av=av+a.s;
av=av/N;
for(i=0;i<N;i++)
if(a.s<av) b=a;
*n=j;
return av;
}
main()
{STRECs={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85},
{"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87}};
STRECh,t;FILE *out ;
inti,j,n;doubleave;
ave=fun( s,h,&n );
printf("The %d student data which is lower than %7.3f:\n",n,ave);
for(i=0;i<n; i++)
printf("%s%4.1f\n",h.num,h.s);
printf("\n");
out = fopen("out.dat","w") ;
fprintf(out, "%d\n%7.3f\n", n, ave);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(h.s>h.s) {t=h ;h=h; h=t;}
for(i=0;i<n; i++)
fprintf(out,"%4.1f\n",h.s);
fclose(out);
}
int i , j; j=0
改为int i , j; j=0;
就没错了。 谢谢
页:
[1]