#includestdio.h
创新互联建站专业为企业提供上城网站建设、上城做网站、上城网站设计、上城网站制作等企业网站建设、网页设计与制作、上城企业网站模板建站服务,10余年上城做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
float f(float a,float b,float c,float x)
{
float y;
y=a*x*x+b*x+c;
return y;
}
void main()
{
float a,b,c,x;
printf("请输入a,b,c,x的值\n");
scanf("%f%f%f%f",a,b,c,x);
printf("%f\n",f(a,b,c,x));
}
也可以把a,b,c改为定植 望采纳 谢谢
#include
int
main()
{
int
n,m;
int
i;
double
s=0;
printf("Please
input
two
numbers.For
example,3,7\n");
scanf("%d
%d",n,m);
for(i=n;i
追问:
在主函数中调用一个函数求这个值怎么搞?
谢谢
评论
加载更多
简单的说就是整数阶乘的推广,它有一个积分的表达式:
Γ(x)=∫e^(-t)*t^(x-1)dt (积分的下限式0,上限式+∞)
算法源自《常用算法程序集》徐士良
#include "stdio.h"
double gam1(x)
double x;
{ int i;
double y,t,s,u;
static double a[11]={ 0.0000677106,-0.0003442342,
0.0015397681,-0.0024467480,0.0109736958,
-0.0002109075,0.0742379071,0.0815782188,
0.4118402518,0.4227843370,1.0};
if (x=0.0)
{ printf("err**x=0!\n"); return(-1.0);}
y=x;
if (y=1.0)
{ t=1.0/(y*(y+1.0)); y=y+2.0;}
else if (y=2.0)
{ t=1.0/y; y=y+1.0;}
else if (y=3.0) t=1.0;
else
{ t=1.0;
while (y3.0)
{ y=y-1.0; t=t*y;}
}
s=a[0]; u=y-2.0;
for (i=1; i=10; i++)
s=s*u+a[i];
s=s*t;
return(s);
}
#include stdio.h
#include stdlib.h
//高精度计算s=1/n+1/(n+1)+1/(n+2)+……+1/m表达式的值
//求得的s是个分数,分子放在result[0]中,分母放在result[1]中
void func(double *result)
{
int m, n, i;
double *numerator; //分子
printf("Please input n and m (Separate by space and 0nm): \n");
while(scanf("%d%d", n, m))
{
if((0 n) (n m))
break;
printf("Value Invalid, please try again!\n");
printf("Please input n and m (Separate by space and 0nm): \n");
}
numerator = (double *)calloc(m, sizeof(double));
if(!numerator)
{
printf("malloc failed!\n");
exit(0);
}
result[1] = 1;
//下面两个for循环是进行通分
for(i=n; i=m; i++)
result[1] *= i;
for(i=n; i=m; i++)
numerator[i-n] = result[1]/i;
result[0] = 0;
//对分母进行相加
for(i=n; i=m; i++)
result[0] += numerator[i-n];
for(i=n; im; i++)
printf("1/%d + ", i);
printf("1/%d = ", m);
free(numerator);
}
int main()
{
double result[2];
func(result);
printf("%g/%g\n", result[0], result[1]);
return 0;
}
//如果你还想对结果化为最简分数的话,可以告诉我,我会改程序