标题:大家帮我看看这个程序 谢谢
取消只看楼主
z974532452
Rank: 2
等 级:论坛游民
帖 子:23
专家分:41
注 册:2015-5-10
结帖率:75%
已结贴  问题点数:20 回复次数:2 
大家帮我看看这个程序 谢谢
#include <stdio.h>
#include<stdlib.h>
int main(void)
{
    FILE *fp;
    long num;
    char stname[20];
    int i,j,k,score[10];
    int max,min;
    if((fp=fopen("D:\\f12-1.txt","r"))==NULL)
    {
        printf("File open error!\n");
        exit(0);
    }
    for(i=0;i<5;i++)
    {
        fscanf(fp,"%ld%s%d",&num,stname,&score[i]);
        printf("%ld %s %d\n",num,stname,score[i]);
    }
    printf("output max:");
    for(j=0;j<5;j++)
    {
        max=score[0];
        if(max<score[j])
        {
            max=score[j];
        }
    }
    printf("%ld %s %d\n",num,stname,max);//怎样才能输出第j个人的学号和姓名
    printf("output min:");
    for(k=0;k<5;k++)
    {
        min=score[0];
        if(min>score[k])
        {
            min=score[k];
        }
    }
    printf("%ld %s %d\n",num,stname,min);//怎样才能输出第k个人的学号和姓名
    if(fclose(fp))
    {
        printf("Can not close the file!\n");
        exit(0);
    }
    return 0;
}
输出结果如下:
301101 Zhangwen 91
301102 Chenhui 85
301103 Wangweidong 76
301104 Zhengwei 69
301105 Guowentao 55

301105 Guowentao 91
301105 Guowentao 55
我试了好好长时间也试不出怎样才能得到最高分数和最低分数人的学号和姓名,我这样写的程序只能输出最高分数和最低分数但就是不会怎样才鞥输出对应的人的学号和姓名
搜索更多相关主题的帖子: include 
2015-05-28 17:08
z974532452
Rank: 2
等 级:论坛游民
帖 子:23
专家分:41
注 册:2015-5-10
得分:0 
回复 4楼 do8do8do8
输不出结果啊
2015-05-28 21:15
z974532452
Rank: 2
等 级:论坛游民
帖 子:23
专家分:41
注 册:2015-5-10
得分:0 
回复 4楼 do8do8do8
刚研究了下  先要k=0; 谢谢
2015-05-28 21:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-445896-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.118849 second(s), 10 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved