實驗7

第一題 #include<stdio.h> int main() {code

FILE *fp1,*fp2;
int a[10];
int i=0,j,sum=0;
if((fp1=fopen("d:\\test1.txt","r"))==NULL){
    printf("can not open file\n");
	exit(0);
}
while(!feof(fp1)){
    fscanf(fp1,"%d",&a[i]);
	i++;
}
for(j=0;j<10;j++){
    sum+=a[j];
}
fclose(fp1);

if((fp2=fopen("d:\\test2.txt","w"))==NULL){
    printf("can not open file\n");
	exit(0);
}

fprintf(fp2,"%d",sum);
fclose(fp2);
return 0;

}it

相關文章
相關標籤/搜索