回 帖 发 新 帖 刷新版面

主题:帮帮改改,找不出错在哪里了。

#include<stdio.h>
#define N 10
#define M 5
float score[N][M];                   /*全局数组*/
float a_stu[N],a_cour[M];                /*全局数组*/
int r,c;                                     /*全局变量*/
   void main()
{int i,j;
float h,l;
float lowest();                            /*函数声明*/                         
float highest();                               /*函数声明*/ 
void input_stu(void);                          /*函数声明*/ 
void aver_stu(void);                            /*函数声明*/  
void aver_cour(void);                             /*函数声明*/ 
input_stu();                                      /*函数调用,输入10个学生成绩*/ 
aver_stu();                          /*函数调用,计算10个学生平均成绩*/   
aver_cour();                                 /*函数调用,计算5门课的平均成绩*/
printf("\n    NO.   cout1   cour2  cour3  cour4   cour5   aver\n");
  for(i=0;i<N;i++)
  {printf("NO. %2d",i+1);                   /*输入1个学生号*/     
    for(j=0;j<M;j++)
       printf("%8.2f",score[i][j]);              /*输入1个学生的各门课的成绩*/       
             printf("%8.2f\n",a_stu[i]); /*输入1个学生的平均成绩*/ 
  }
printf("\naverge:");
for(j=0;j<M;j++)           /*输入5门课的平均成绩*/ 
    printf("%8.2f",a_cour[j]);
printf("\n");
h=highest();       /*调用函数,求最高分*/ 
l=lowest();          /*调用函数,求最低分*/
printf("highest: %7.2f lowest: %7.2f \n",h,l);       /*输出最高分,最低分*/
}
void input_stu(void)                      /*输入10个学生成绩的函数*/
{int i,j;
    for(i=0;i<N;i++)
    {printf("\ninput score of student%2d:\n",i+1);
       for(j=0;j<M;j++)
        scanf("%f",&score[i][j]);
    }
}
void aver_stu(void)       /*计算10个学生平均成绩的函数*/
{int i,j;
float s;
         for(i=0;i<N;i++)
         {for(j=0,s=0;j<M;j++)
                s+=score[i][j];
            a_stu[i]=s/5;
         }
}
void aver_cour(void)         /*计算5门课的平均成绩的函数*/
{int i,j;
float s;
         for(j=0;j<M;j++)
         {s=0;
          for(i=0;i<N;i++)
           s+=score[i][j];
          a_cour[j]=s/(float)N;
         }
}
float highest()       /*计算最高分的函数*/
{float high;
int i,j;
high=score[0][0];
      for(i=0;i<N;i++)
     for(j=0;j<M;j++)
      if(score[i][j]>high) 
      {high=score[i][j];
      c=j+1;
      }
  return(high);
      
     
}
float lowest()           /*计算最低分的函数*/
{float low;
int i,j;
      low=score[0][0];
        for(i=0;i<N;i++)
    for(j=0;j<M;j++)
        if(score[i][j]<low) 
    {low=score[i][j];
        c=j+1;}
          return(low);
        
    
}




调试程序时,总显示有一个错误啊,在那里啊?

回复列表 (共2个回复)

沙发

调试了一下,没出现问题

板凳

你可能是在turbo c中运行的吧!我在turbo c中运行也出现了问题,不知道为什么!但是在vc++中运行就成功了,结果输出也是正确 的,你的程序在vc++中运行完全没有问题,可能我们的turbo c少了一个什么组件的,

我来回复

您尚未登录,请登录后再回复。点此登录或注册