gpt4 book ai didi

c - 编译过程中出现错误?

转载 作者:行者123 更新时间:2023-11-30 19:58:50 25 4
gpt4 key购买 nike

我尝试为卡方PDF编写一个函数;但是我收到以下错误:

Q4.c: In function ‘GAMMA’:Q4.c:31:2: error: expected identifier or ‘(’ before ‘long’Q4.c:37:2: error: expected ‘(’ before ‘{’ tokenQ4.c:38:3: error: ‘factor’ undeclared (first use in this function)Q4.c:38:3: note: each undeclared identifier is reported only once for each function it appears inQ4.c:43:4: error: ‘multiplier’ undeclared (first use in this function)

I am unable to figure out the why I get this error. I would appreciate it if you provide some suggestions or insight.

#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>
long double factorial (long double);
//Now we define it,
long double
factorial(long double n)
{
//Here s is the free parameter which is increased by one in each step and
//pro is the initial product and by setting pro to be 0 we also cover the
//case of zero factorial.
int s = 1;
long double pro = 1;
//Here pro stands for product.
if (n < 0)
printf("Factorial is not defined for a negative number \n");
else {
while (n >= s) {
pro *= s;
s++;
}
return pro;
}
}
long double GAMMA(int);
long double
GAMMA(int v)
{
int i = 1,
long double factor, multiplier = sqrtl(M_PI);
if((v % 2) == 0)
{
return factorial((v / 2) - 1);
}
else if
{
factor = (v / 2) - i;
while(v / 2 - (i + 1) > 0)
{
i++;
factor = v / 2 - i;
multiplier *= factor;
}
return multiplier;
}
}
long double ChisquarePDF(long double, int);
long double
ChisquarePDF(long double x, int v)
{
return powl(x, v/2 - 1) / ( powl(2, v/2) * GAMMA(v / 2) * expl(x / 2)) ;
}
int main()
{
printf("%Lf \n", GAMMA(5));
}

最佳答案

本声明:

int i = 1,
long double factor, multiplier = sqrtl(M_PI);

应该用分号分隔:

int i = 1;
long double factor, multiplier = sqrtl(M_PI);

关于c - 编译过程中出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20269575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com