c语言调用纠错

来源:百度知道 编辑:UC知道 时间:2024/04/30 15:10:52
#include <stdio.h>
#define ALL_NUMBER 40

int Select (score[],int n);

int main ()
{
int number[ALL_NUMBER];
float score[ALL_NUMBER];
int n;
int i;
int k=0;

printf("please input the number and the score");
scanf("%d",&n);

for (i=0;i<=n-1;i++)
{
scanf("%d %f",&number[i],&score[i]);
}

k=Select(score,n);

printf("%d,%.0f",number[k],score[k]);

return 0;
}

int Select(score[],int n)
{

float mark;
int k;
int i;
mark=score[0];
for(i=1;i<=n-1;i++)
{
if(score[i]>mark)
{
mark=score[i];
k=i;
}
}
return k;
}

运行不会出现异常错误了,问题出在初始化
#include <stdio.h>
#define ALL_NUMBER 40

int Select (float score[],int n); //函数的声明注意:写出形参的类型

int main ()
{
int number[ALL_NUMBER]={0};
float score[ALL_NUMBER]={0.0};
int n;
int i;
int k=0;

printf("please input the number and the score\n");
scanf("%d",&n);

for (i=0;i<=n-1;i++)
{
scanf("%d %f",&number[i],&score[i]);
}

k=Select(score,n);
//printf("k=%d\n",k);

printf("%d,%f",number[k],score[k]);

return 0;
}

int Select(float score[],int n)
{

float mark;
int p=0; //注意,这里要赋初值
int i;
mark=score[0];
for(i=1;i<=n-1;i++)
{
if(score[i]>mark)
{
mark=score[i];
p=i;

}
}
//printf("p=%d\n",p);
retu