zoukankan      html  css  js  c++  java
  • 第二周基础作业

    基础作业
    请在第一周作业的基础上,继续完成:找出给定的文件中数组的最大值及其对应的最小下标(下标从0开始)。并将最大值和对应的最小下标数值写入文件。
    输入:
    请建立以自己英文名字命名的txt文件,并输入数组元素数值,元素值之间用逗号分隔。
    输出
    在不删除原有文件内容的情况下,将最大值和对应的最小下标数值写入文件。

    实验代 #include<stdio.h>

    #include<stdlib.h>
    int main ()
    {
        FILE * fp;
        int a[10], i, max, j;
        if((fp=fopen("D:\\homework\\ZHANGCHANGQINLEI.txt","r+"))==NULL)
        {
        printf("File open error!\n");
        exit(0);
        } 
        
        for(i=0;i<6;i++)
        {
            fscanf(fp,"%d",&a[i]);
        }
        
        for(i=0; i<6;i++)
       {
         if(i==0)
         {
         max = a[i];
         j = i;
         }
         if(max<a[i])
         {
          max = a[i];
          j = i;
         }
       }
       fprintf(fp,"\n%d %d", max, j);
        if(fclose(fp)) 
        {
            printf("Can not close the file!\n");
            exit(0);
         } 
         return 0;
    }
     
  • 相关阅读:
    Python对象
    python 迭代器和生成器
    python中logging日志模块详解
    学习中遇到的一些问题(杂谈)
    如何在github上搜索项目
    python闭包与装饰器
    python面试题
    selenium
    python导入自定义包
    About Me、
  • 原文地址:https://www.cnblogs.com/zc00/p/10502407.html
Copyright © 2011-2022 走看看