2019年春季学期第二周作业基础作业请在第一周作业的基础上,继续完成:找出给定的文件中数组的最大值及其对应的最小下标(下标从0开始)。并将最大值和对应的最小下标数值写入文件。
代码:
#include<stdio.h>#include<stdlib.h>int main(void){ FILE * fp; int i,m,n; int a[5]; if((fp=fopen("C:\\Users\\69404\\Desktop\\CGP\\CGP.txt","r+"))==NULL) { printf("File open error!\n"); exit(0); } for(i=0;i<5;i++) { fscanf(fp,"%d",&a[i]); } m=a[0]; for(i=0;i<5;i++){ if(m<a[i]) m=a[i]; n=i; } fprintf(fp,"\n%d %d",m,n); if(fclose(fp)){ printf("Can not close the file!\n"); exit(0); } return 0;}
设计思路:
遇到的问题及其解决方法:
没有将文本文档与程序放在同一文件夹内进行编译运行
运行结果图
在之前mooc上的教学视频太繁琐跳过导致有些学过疏忽的地方还是有一些一直半解还是助教的视频给了很大的帮助
转载于:https://www.cnblogs.com/cgp233333/p/10502749.html
相关资源:DirectX修复工具V4.0增强版