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

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

     实验代码

    #include<stdio.h>
    #include<stdlib.h>
    int main(){
    FILE*fp;
    int n,i,max;
    int a[10];
    if((fp=fopen("F:\C\liujin.txt","w+"))==NULL)
    {
    printf("File open error! ");
    exit(0);
    }
    scanf("%d",&n);
    fprintf(fp,"%d ",n);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    fprintf(fp,"%d",a[0]);
    for(i=1;i<n;i++)
    fprintf(fp,",%d",a[i]);
    max=0;
    for(i=0;i<n;i++)
    if(a[i]>a[max])
    max=i;
    printf("%d %d",a[max],max);
    fprintf(fp," %d %d",a[max],max);
    if(fclose(fp)){
    printf("Can not close the file! ");
    exit(0);
    }
    return 0;
    }

     

     在室友的帮忙下完成 感觉自己很多东西都知道
  • 相关阅读:
    模块jieba库的使用
    模块wordcloud库的使用
    爬取哔哩哔哩网站弹幕
    爬虫讲解
    基本统计值计算
    数据类型及元素元组
    pyinstall的安装及使用
    面向对象介绍
    re模块
    logging模块
  • 原文地址:https://www.cnblogs.com/liu99/p/10502455.html
Copyright © 2011-2022 走看看