c语言问题,求高手解答。
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#defineN10#defin...
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define N 10
#define M 5
float score[N][M]; //知识点 :数组
double a_stu[N],a_cour[M];
int r, c;
void main()
{
int i,j;
float h;
float s_var(void);
float higest();
void input_stu(void); //知识点: 函数调用
void aver_stu(void); //函数声明
void aver_cour(void);
input_stu();
aver_stu();
aver_cour();
s_var();
printf ("\n No. cour cour2 cour3 cour4 cour5 aver \n");
for (i=0;i<N;i++) //知识点;: for循环
{printf("\n NO %2d",i+1);
for (j=0;j<M;j++)
{printf("%8.2f",score[i][j]);
printf("%8.2f\n",a_stu[i]);
}
printf("\n average :"); //输出五门课成绩
for (j=0;j<M;j++)
printf("%8.2f",a_cour[j]);
printf("\n");
h=higest();
printf ("higest: %7.2f No. %2d course %2d\n",h,r,c );
printf ("variance%8.2f \n",s_var());
}
void input_stu(void) //输入十个学生成绩的函数
{
int i,j;
for (i=0;i<N;i++)
printf ("\n input score of student %2d\n",i+1);
for (j=0;j<M;j++)
scanf("%f",score[i][j]);
}
}
void aver_stu(void) //计算十个学生平均成绩的函数
{int i,j;
double s;
for (i=0;i<N;i++) ;
{for (j=0,s=0;j<M;j++);
s+=score[i][j];
a_stu[i]=s/5.0;
}
}
void aver_cour(void) //计算五门课平均成绩的函数
{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 higest()
{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];
r =i+1;
c =j=1;
}
return (high);
}
float s_var(void); //求方差的函数
{
int i,N;
float sumx,sumxn;
float t
sumx=0.0;
sumxn=0.0;
for (i=0;i<N;i++)
{sumx+ =a_stu[i]*a_stu[i];
sumxn+ =a_stu[i];
t=sumx/N-(sumxn/N)*(sumxn/N)
}
return (t);
}
出现错误
--------------------Configuration: eee - Win32 Debug--------------------
Compiling...
eee.cpp
C:\Users\lenovo\Desktop\c疑问\eee.cpp(39) : error C2601: 'input_stu' : local function definitions are illegal
C:\Users\lenovo\Desktop\c疑问\eee.cpp(80) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.
eee.obj - 2 error(s), 0 warning(s) 展开
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define N 10
#define M 5
float score[N][M]; //知识点 :数组
double a_stu[N],a_cour[M];
int r, c;
void main()
{
int i,j;
float h;
float s_var(void);
float higest();
void input_stu(void); //知识点: 函数调用
void aver_stu(void); //函数声明
void aver_cour(void);
input_stu();
aver_stu();
aver_cour();
s_var();
printf ("\n No. cour cour2 cour3 cour4 cour5 aver \n");
for (i=0;i<N;i++) //知识点;: for循环
{printf("\n NO %2d",i+1);
for (j=0;j<M;j++)
{printf("%8.2f",score[i][j]);
printf("%8.2f\n",a_stu[i]);
}
printf("\n average :"); //输出五门课成绩
for (j=0;j<M;j++)
printf("%8.2f",a_cour[j]);
printf("\n");
h=higest();
printf ("higest: %7.2f No. %2d course %2d\n",h,r,c );
printf ("variance%8.2f \n",s_var());
}
void input_stu(void) //输入十个学生成绩的函数
{
int i,j;
for (i=0;i<N;i++)
printf ("\n input score of student %2d\n",i+1);
for (j=0;j<M;j++)
scanf("%f",score[i][j]);
}
}
void aver_stu(void) //计算十个学生平均成绩的函数
{int i,j;
double s;
for (i=0;i<N;i++) ;
{for (j=0,s=0;j<M;j++);
s+=score[i][j];
a_stu[i]=s/5.0;
}
}
void aver_cour(void) //计算五门课平均成绩的函数
{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 higest()
{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];
r =i+1;
c =j=1;
}
return (high);
}
float s_var(void); //求方差的函数
{
int i,N;
float sumx,sumxn;
float t
sumx=0.0;
sumxn=0.0;
for (i=0;i<N;i++)
{sumx+ =a_stu[i]*a_stu[i];
sumxn+ =a_stu[i];
t=sumx/N-(sumxn/N)*(sumxn/N)
}
return (t);
}
出现错误
--------------------Configuration: eee - Win32 Debug--------------------
Compiling...
eee.cpp
C:\Users\lenovo\Desktop\c疑问\eee.cpp(39) : error C2601: 'input_stu' : local function definitions are illegal
C:\Users\lenovo\Desktop\c疑问\eee.cpp(80) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.
eee.obj - 2 error(s), 0 warning(s) 展开
展开全部
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define N 10
#define M 5
float score[N][M]; //知识点 :数组
double a_stu[N],a_cour[M];
int r, c;
int main()
{
int i,j;
float h;
float s_var(void);
float higest();
void input_stu(void); //知识点: 函数调用
void aver_stu(void); //函数声明
void aver_cour(void);
input_stu();
aver_stu();
aver_cour();
s_var();
printf ("\n No. cour cour2 cour3 cour4 cour5 aver \n");
for (i=0;i<N;i++) //知识点;: for循环
{printf("\n NO %2d",i+1);
for (j=0;j<M;j++)
{printf("%8.2f",score[i][j]);
printf("%8.2f\n",a_stu[i]);
}
printf("\n average :"); //输出五门课成绩
}
for (j=0;j<M;j++)
printf("%8.2f",a_cour[j]);
printf("\n");
h=higest();
printf ("higest: %7.2f No. %2d course %2d\n",h,r,c );
printf ("variance%8.2f \n",s_var());
return 0;
};
void input_stu(void) //输入十个学生成绩的函数
{
int i,j;
for (i=0;i<N;i++)
printf ("\n input score of student %2d\n",i+1);
for (j=0;j<M;j++)
scanf("%f",score[i][j]); 数组越界了,注意 i已经等于N了,那么你这个数组就有问题了,而求你要求输入的分数个不对
}
void aver_stu(void) //计算十个学生平均成绩的函数
{int i,j;
double s;
for (i=0;i<N;i++) ;
{for (j=0,s=0;j<M;j++);
s+=score[i][j];
a_stu[i]=s/5.0;
}
};
void aver_cour(void) //计算五门课平均成绩的函数
{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 higest()
{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];
r =i+1;
c =j=1;//写错了吧
};
return (high);
};
float s_var(void) //求方差的函数{
{int i;
float sumx,sumxn;
float t;
sumx=0.0;
sumxn=0.0;
for(i=0;i<N;i++)
{sumx +=a_stu[i]*a_stu[i];
sumxn +=a_stu[i];
t=sumx/N-(sumxn/N)*(sumxn/N);
};
return (t);
}
语法是没错误了 不过运行会有问题啊
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define N 10
#define M 5
float score[N][M]; //知识点 :数组
double a_stu[N],a_cour[M];
int r, c;
int main()
{
int i,j;
float h;
float s_var(void);
float higest();
void input_stu(void); //知识点: 函数调用
void aver_stu(void); //函数声明
void aver_cour(void);
input_stu();
aver_stu();
aver_cour();
s_var();
printf ("\n No. cour cour2 cour3 cour4 cour5 aver \n");
for (i=0;i<N;i++) //知识点;: for循环
{printf("\n NO %2d",i+1);
for (j=0;j<M;j++)
{printf("%8.2f",score[i][j]);
printf("%8.2f\n",a_stu[i]);
}
printf("\n average :"); //输出五门课成绩
}
for (j=0;j<M;j++)
printf("%8.2f",a_cour[j]);
printf("\n");
h=higest();
printf ("higest: %7.2f No. %2d course %2d\n",h,r,c );
printf ("variance%8.2f \n",s_var());
return 0;
};
void input_stu(void) //输入十个学生成绩的函数
{
int i,j;
for (i=0;i<N;i++)
printf ("\n input score of student %2d\n",i+1);
for (j=0;j<M;j++)
scanf("%f",score[i][j]); 数组越界了,注意 i已经等于N了,那么你这个数组就有问题了,而求你要求输入的分数个不对
}
void aver_stu(void) //计算十个学生平均成绩的函数
{int i,j;
double s;
for (i=0;i<N;i++) ;
{for (j=0,s=0;j<M;j++);
s+=score[i][j];
a_stu[i]=s/5.0;
}
};
void aver_cour(void) //计算五门课平均成绩的函数
{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 higest()
{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];
r =i+1;
c =j=1;//写错了吧
};
return (high);
};
float s_var(void) //求方差的函数{
{int i;
float sumx,sumxn;
float t;
sumx=0.0;
sumxn=0.0;
for(i=0;i<N;i++)
{sumx +=a_stu[i]*a_stu[i];
sumxn +=a_stu[i];
t=sumx/N-(sumxn/N)*(sumxn/N);
};
return (t);
}
语法是没错误了 不过运行会有问题啊
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
46行多了个大括号
80行float f;少了个分号
80行float f;少了个分号
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
input_stu 函数中多了一个大括号吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
46行多了个大括号
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询