c语⾔求定积分的程序,C语⾔实现求定积分的⽅法#include
#include
#define ACC 1000
float solve(float (*p)(float),float up,float down,int acc);
float fun_exp(float x);
float fun_qua(float x);
void main(){
char selection;
float up,down;
while(printf("请选择被积函数:\n"),printf("1、exp(x)  2、x+1 \n"),scanf("%c",&selection),selection != '#'){
printf("请输⼊积分上下限: ");
scanf("%f,%f",&up,&down);
switch(selection){
case '1':
printf("结果是: %4.4f\n",solve(fun_exp,up,down,ACC));
break;
case '2':
printf("结果是: %4.4f\n",solve(fun_qua,up,down,ACC));
break;
}
}
}
float solve(float (*p)(float),float up,float down,int acc){
float sum,base,area;
area = 0;
sum = 0;
base = (up-down)/acc;c语言下载什么
for(int i=0; i
area = base*((*p)(down+i*base));
sum+=area;
}
return sum;
}
float fun_exp(float x){
return exp(x);
}
float fun_qua(float x){ //⼀元⼆次⽅程 quadratics return x+1;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。