|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
float Max=0,Min=0;
void main()
{
float average(float array[],int n);
float ave,score[10];
int i;
for(i=0;i<10;i++)
{
scanf("%f",&score[i]);
}
ave=average(score,10);
printf("max=%6.2f\nmin=%6.2f\naverage=%6.2f\n",Max,Min,ave);
}
float average(float arry[],int n)
{
int i;
float aver,sum=array[0];
Max=Min=array[0];
for(i=1;i<n;i++)
{
if(array[i]>Max)
Max=array[i];
else if(array[i]<Min)
Min=array[i];
sum +=array[i];
}
aver=sum/n;
return aver;
}
这个程序是对着小甲鱼老师视频抄的,但是编译报错了,
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(23) : error C2065: 'array' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(23) : error C2109: subscript requires array or pointer type
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(23) : warning C4244: 'initializing' : conversion from 'int ' to 'float ', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(24) : error C2109: subscript requires array or pointer type
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(24) : warning C4244: '=' : conversion from 'int ' to 'float ', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(28) : error C2109: subscript requires array or pointer type
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(29) : error C2109: subscript requires array or pointer type
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(29) : warning C4244: '=' : conversion from 'int ' to 'float ', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(30) : error C2109: subscript requires array or pointer type
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(31) : error C2109: subscript requires array or pointer type
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(31) : warning C4244: '=' : conversion from 'int ' to 'float ', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\hanshu11\hanshu11.c(32) : error C2109: subscript requires array or pointer type
执行 cl.exe 时出错.
hanshu11.obj - 1 error(s), 0 warning(s)
是怎么回事啊,是不是我下载的软件有问题?
#include <stdio.h>
float Max=0,Min=0;
void main()
{
float average(float array[],int n);
float ave,score[10];
int i;
for(i=0;i<10;i++)
{
scanf("%f",&score[i]);
}
ave=average(score,10);
printf("max=%6.2f\nmin=%6.2f\naverage=%6.2f\n",Max,Min,ave);
}
float average(float arry[],int n)
{
int i;
float aver,sum=array[0];
Max=Min=array[0];
for(i=1;i<n;i++)
{
if(array[i]>Max)
Max=array[i];
else if(array[i]<Min)
Min=array[i];
sum +=array[i];
}
aver=sum/n;
return aver;
}
你都不愿意看代码吗?
|
|