将数组b中大于x的数顺序复制到数组a中,并在主函数中将a数组的内容输出

#include<stdio.h>
int i,j,n=9;
double x;
void main()
{
void select(int n, double a[], double b[], double x);
double a[9],b[]={0,1.4,5.2,6.8,7.4,9.0,12.5,17.8,24.5};
printf("please input :x=");
scanf("%g",&x);
select(int n, double a[9], double b[9], double x);
for(i=0;i<n;i++)
printf("%g ",*(a+i));
printf("\n");
}

void select(int n, double a[], double b[], double x)
{
i=0;
for(j=0;j<n;j++)
if(*(b+j)>x)
{
*(a+i)=*(b+j);
i+=1;
}
}

//在主函数中定义数组a和b,并用若干个实数将b初始化。
//写一个函数 select(int n, double a[], double b[], double x) ,
//它将数组b中大于x的数顺序复制到数组a中,并在主函数中将a数组的内容输出。
//a数组的内容为空,n是两个数组的大小。(提示:a和b数组分别用两个计数器i和j计算下标,一般i<=j)
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2133: 'a' : unknown size
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
Error executing cl.exe.
最新回答
痘肤西施

2025-03-26 13:29:00

#include<stdio.h>
int i,j,n=9;
double x;
void main()
{
void select(int n,double ai[], double b[], double x);
double a[9] = {0},b[]={0,1.4,5.2,6.8,7.4,9.0,12.5,17.8,24.5};
printf("please input :x=");
scanf("%lf",&x);
printf("%f\n", x);
select(n,a, b,x);
for(i=0;i<n;i++)
if (*(a+i)>0)
printf("%g ",*(a+i));
printf("\n");
}

void select(int n,double a[], double b[], double x)
{
i=0;
for(j=0;j<n;j++)
if(*(b+j)>x)
{
*(a+i)=*(b+j);
i+=1;
}
心头的小情儿

2025-03-26 11:37:02

#include<stdio.h>
int i,j,n=9;
double x;
void main()
{
double a[9],b[]={0,1.4,5.2,6.8,7.4,9.0,12.5,17.8,24.5};
printf("please input :x=");
scanf("%g",&x);
for(i=0;i<9;i++)
if(b[i]>x)
{
a[i]=b[i];
}
for(i=0;i<n;i++)
printf("%g ",a[i]);
printf("\n");
}
春风正得意

2025-03-26 08:45:19

a数组的内容为空,n是两个数组的大小 select(int n,double a[],double b[],double x) { int i,m=0; for(i=0;i
追问
??
鱼沉秋水

2025-03-26 09:27:37

主函数第二句select(int n, double a[9], double b[9], double x);改为
select(n, a[9], b[9], x);