用矩形法求定積分的通用函數(shù)

時間:2018-12-31 12:00:00 資料大全 我要投稿

用矩形法求定積分的通用函數(shù)

  解: #include

  main()

  { float integral(float(8p)(float),float a,float b,int n);

  float a1,b1,a2,b2,a3,b3,c,(*p)(float);

  float fsin(float);

  float fcos(float);

  float fexp(float);

  int n=20;

  printf(“Input a1,b1:”);

  scanf(“%f,%f”,&a1,&b2);

  printf(“Input a2,b2:”);

  scanf(“%f,%f”,&a2,&b2);

  printf(“Input a3,b3:”);

  scanf(“%f,%f”,&a3,b3);

  p=fsin;

  c=integral(p,a1,b1,n);

  printf(“The integral of sin(x) is:%f\n”,c);

  p=fcos;

  c=integral(p,a2,b2,n);

  printf(“The integral of cos(x) is :%f\n”,c);

  c=integral(p,a3,b3,n);

  printf(“The integral of sin(x) is :%f\n”,c);

  }

  float integral(float (*p)(float),float a,float b,int n)

  {

  int i;

  floatx,h,s;

  h=(b-a)/n;

  x=a;

  s=0;

  for(i=1;i<=n;i++)

  {x=x+h;

  s=s+(*p)(x)*h;

  }

  return(s);

  }

  float fsin(float x)

  {return sin(x);}

  float fcos(float x)

  {return cos(x);}

  float fexp(float x)

  {return exp(x);}

【用矩形法求定積分的通用函數(shù)】相關(guān)文章:

1.學習高數(shù)定積分計算常用技巧

2.反面試法怎么用

3.PHP解析URL是哪個函數(shù)?怎么用?

4.初中數(shù)學說課稿《矩形的判定》

5.tatic函數(shù)與普通函數(shù)的區(qū)別

6.求英語自我介紹(面試時用的)

7.編寫類String 的構(gòu)造函數(shù)、析構(gòu)函數(shù)和賦值函數(shù)

8.用“八字法”學習政治