本人有一题不明白,模拟题来的: #include <stdio.h> #include <conio.h> #define N 20 fun( int *a,int n,int *odd,int *even) {int i;*even=0;*odd=0; for(i=0;i<n;i++) {if(a[i]%2==0) *even=*even+a[i]; else *odd=*odd+a[i]; }
} main() { int a[N]={1,9,2,3,11,6},i,n=6,odd,even; clrscr(); printf("The original data is:\n"); for (i=0;i<n;i++) printf("%5d",*(a+i)); printf("\n\n"); fun(a,n,&odd,&even); printf("The sum of odd numbers: %d\n",odd); printf("The sum of even numbers: %d\n",even); NONO( ); }
NONO( ) {/* 请在此函数内打开文件,输入测试数据,调用 fun 函数, 输出数据,关闭文件。 */ int i, j, odd, even, n, a[N] ; FILE *rf, *wf ;
rf = fopen("bc7.in", "r") ; wf = fopen("bc7.out", "w") ; for(i = 0 ; i < 10 ; i++) { fscanf(rf, "%d", &n) ; for(j = 0 ; j < n ; j++) fscanf(rf, "%d", a+j) ; fun(a, n, &odd, &even) ; fprintf(wf, "odd=%d,even=%d\n", odd, even) ; } fclose(rf) ; fclose(wf) ; }
结果是正确的,但模拟环境说我bc7.out文件有问题。 请大家帮帮我!!