zoukankan      html  css  js  c++  java
  • 第二次作业

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

    
    第二次实验代码
    #include<stdio.h>
    #include<stdlib.h>
    int main()
    {
     FILE *fp;
     int a[10],b,i,c;
     if((fp=fopen("C:\Users\Lenovo\Desktop\text.txt","a+"))==NULL)
     {
      printf("File open error!
    ");
      exit (0);
     }
     fscanf(fp,"%d,",&i);
     printf("%d ",i);
     for(b=0;b<i;b++){
      fscanf(fp,"%d",&a[b]);
      printf("%d ",a[b]);
      if(b+1==i){
       printf("
    ");
      }
     }
     for(c=b=0;b<i-1;b++){
     if(a[c]<a[b+1]){
         c=b+1;
        }
     }
     printf("%d  %d",a[c],c);
     fprintf(fp,"
    %d  %d",a[c],c);
     if(fclose(fp)){
      printf("Can not close the file!
    ");
      exit(0);
     }
     return 0;
    }#include<stdio.h>
    #include<stdlib.h>
    int main()
    {
     FILE *fp;
     int a[10],b,i,c;
     if((fp=fopen("C:\Users\Lenovo\Desktop\text.txt","a+"))==NULL)
     {
      printf("File open error!
    ");
      exit (0);
     }
     fscanf(fp,"%d,",&i);
     printf("%d ",i);
     for(b=0;b<i;b++){
      fscanf(fp,"%d",&a[b]);
      printf("%d ",a[b]);
      if(b+1==i){
       printf("
    ");
      }
     }
     for(c=b=0;b<i-1;b++){
     if(a[c]<a[b+1]){
         c=b+1;
        }
     }
     printf("%d  %d",a[c],c);
     fprintf(fp,"
    %d  %d",a[c],c);
     if(fclose(fp)){
      printf("Can not close the file!
    ");
      exit(0);
     }
     return 0;}
     
     
     !https://i)
    [](mg2018.cnblogs.com/blog/1580496/201903/1580496-20190311133444530-2101791341.png
     
     截图没成功,在另外那个编辑器里头有截图
  • 相关阅读:
    [NOIp pj 2007][Luogu P1095] 守望者的逃离
    [Noip 2009 普及组 T4] [Luogu P1070] 道路游戏
    跟风Manacher算法整理
    Luogu P2569 [SCOI2010] 股票交易
    qbzt2020五一DAY1T1集合——题解
    Cena使用教程
    2020.4.15校内测试
    康托展开学习笔记
    qbzt网格图路径问题——题解
    2-sat基础详解
  • 原文地址:https://www.cnblogs.com/ydlBLOG/p/10510099.html
Copyright © 2011-2022 走看看