标签:style blog io color sp for div log bs
#include<stdio.h> double f(float x) { return x*x+x; } double definf(float a,float b,int n) { int k; double h,tmp; h=(b-a)*1.0/n; for(tmp=0,k=1;k<=n-1;k++) tmp+=f(a+k*h); return h*(f(a)+f(b))/2+h*tmp; } int main() { float a,b; double definfresult; int n; do { printf("此程序用复化梯形公式计算f(x)=x^2+x的定积分\n"); printf("积分下限a="); scanf("%f",&a); printf("积分上限b="); scanf("%f",&b); printf("划分个数n="); scanf("%d",&n); definfresult=definf(a,b,n); printf("下限为%.2f,上限为%.2f时,f(x)的定积分为%.2lf\n\n",a,b,definfresult); }while(n>0); }
标签:style blog io color sp for div log bs
原文地址:http://www.cnblogs.com/fishegg/p/4148288.html