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
     
     截图没成功,在另外那个编辑器里头有截图
  • 相关阅读:
    Android 5.0新特性了解(一)----TabLayout
    Kafka生产者各种启动参数说明
    Kafka基础知识
    ONS发布订阅消息
    Spring异步事件
    Java动态代理机制
    Java线程间怎么实现同步
    技术架构实践三要点
    Distributed transactions in Spring, with and without XA
    Spring 中常用注解原理剖析
  • 原文地址:https://www.cnblogs.com/ydlBLOG/p/10510099.html
Copyright © 2011-2022 走看看