C說話完成求定積分的辦法。本站提示廣大學習愛好者:(C說話完成求定積分的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C說話完成求定積分的辦法正文
本文實例講述了C說話完成求定積分的辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:
#include <cmath>
#include <cstdio>
#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;
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;
}
願望本文所述對年夜家的C說話法式設計有所贊助。