跪求大神帮忙,几个c语言程序答案,在几天内就要交了,感激不尽啊!!!

2024-12-19 19:14:37
推荐回答(3个)
回答1:

double average(double *a, int n);

{
double sum,*pt=a;
sum=0.0;
for(int i=0;i return sum;
}
mian()
{
int num;
double *a;
printf("输入数组元素的个数:");
scanf("%d",&num);
a=(double *)malloc(num);

input(a);
printf(a);
printf("数组所有数的平均值为:%f.",average(a,num));
free(a);
return 0;
}

回答2:

#include
# include
double average(double a[], int n)
{
int i;
double sum=0.0;
for(i=0;i sum+=a[i];
return sum/n;
}
input(double a[],int n)
{
int i;
printf("请输入数据:\n");
for(i=0;i {
scanf("%lf",&a[i]);
}
}
print(double a[],int n)
{
int i;
printf("\n所有数据如下:\n");
for(i=0;i {
printf("%.2lf ",a[i]);
}
}
main()
{
int n;
double *a;
printf("输入数组元素的个数:");
scanf("%d",&n);
a=(double *)malloc(n);
input(a,n);
print(a,n);
printf("\n数组所有数的平均值为:%.2lf.\n",average(a,n));
free(a);
}

回答3:

5分好少的说~