C 气泡分选程序
嗨,我是c语言的新手,当我编译当前代码以查找差异时,我得到以下错误:“]'标记var=var+pow((x[]-my_-mean(n,double x[])之前的预期表达式,2); #包括 #包括 双倍my_var(整数n,双倍x[]); 双倍我的意思(整数n,双倍x[]); 双倍我的总和(整数n,双倍x[])C 气泡分选程序,c,C,嗨,我是c语言的新手,当我编译当前代码以查找差异时,我得到以下错误:“]'标记var=var+pow((x[]-my_-mean(n,double x[])之前的预期表达式,2); #包括 #包括 双倍my_var(整数n,双倍x[]); 双倍我的意思(整数n,双倍x[]); 双倍我的总和(整数n,双倍x[]) int main(无效) { int n=5; 双x[]={4,6,2,7,9}; my_var(n,x); 返回0; } 双倍我的意思(整数n,双倍x[]) { 返回我的金额(n,x)
int main(无效)
{
int n=5;
双x[]={4,6,2,7,9};
my_var(n,x);
返回0;
}
双倍我的意思(整数n,双倍x[])
{
返回我的金额(n,x)/n;
}
双倍我的总和(整数n,双倍x[])
{
int i;
双s=0;
对于(i=0;i您忘记使用循环索引。此外,请从调用中删除类型
var=var+pow((x[i]-my_mean(n,x[i])),2);
好的..我已经用你的代码解决了一些问题..看看::
#include <stdio.h>
#include <math.h>
double my_var(int n, double x[]);
double my_mean(int n, double x[]);
double my_sum(int n, double x[]);
int main (void)
{
int n=5;
double x[]={4, 6, 2, 7, 9};
printf("%f",my_var(n,x));
return 0;
}
double my_mean( int n , double x[])
{
return my_sum(n, x)/ n;
}
double my_sum(int n , double x[])
{
int i;
double s=0;
for( i= 0; i<n ;i++)
{
s = s + x[i];
}
return s;
}
double my_var(int n, double x[])
{
double var=0;
int i;
for (i=0;i<n;i++)
{
var=var+pow((x[i]-my_mean(n,x)),2);
}
return var;
}
#包括
#包括
双倍my_var(整数n,双倍x[]);
双倍我的意思(整数n,双倍x[]);
双倍我的总和(整数n,双倍x[]);
内部主(空)
{
int n=5;
双x[]={4,6,2,7,9};
printf(“%f”,my_var(n,x));
返回0;
}
双倍我的意思(整数n,双倍x[])
{
返回我的金额(n,x)/n;
}
双倍我的总和(整数n,双倍x[])
{
int i;
双s=0;
对于(i=0;i,当您在程序中包含math.h时,您必须通过命令“gcc my_program.c-o my_program-lm”来编译它编译器告诉了您修复该问题所需的所有知识。您至少尝试过什么吗?顺便提一下,在my_var
中,我怀疑您的意思是只计算my_mean
一次,并将其存储在变量中以在循环中使用。my_mean
的第二个参数类型是一个double
数组,而不是do>uble
;)
#include <stdio.h>
#include <math.h>
double my_var(int n, double x[]);
double my_mean(int n, double x[]);
double my_sum(int n, double x[]);
int main (void)
{
int n=5;
double x[]={4, 6, 2, 7, 9};
printf("%f",my_var(n,x));
return 0;
}
double my_mean( int n , double x[])
{
return my_sum(n, x)/ n;
}
double my_sum(int n , double x[])
{
int i;
double s=0;
for( i= 0; i<n ;i++)
{
s = s + x[i];
}
return s;
}
double my_var(int n, double x[])
{
double var=0;
int i;
for (i=0;i<n;i++)
{
var=var+pow((x[i]-my_mean(n,x)),2);
}
return var;
}