编了个求几个定积分的,在switch 后面加return出现错误
#include<stdio.h>
#include<math.h>
int main()
{
void integral(int a, int b, double h);
int a, b;
double h;
h = 0;
printf("input a and b:"); //积分上限a,积分下限b;
scanf("%d,%d", &a, &b);
h = fabs(b - a) / 100;
integral(a,b,h);
return 0;
}
double f(double x)
{
int number;
printf("调用 sinx , cosx , e^x分别按1,2,3: "); //使用三个函数
scanf("%d", &number);
switch(number)
case 1: return sin(x);break; //这里有错误
case 2: return cos(x);break;
case 3: return exp(x);break;
default: printf("default");
}
void integral(int a, int b, double h)
{
double sum = 0;
double fx;
int i;
for(i = 0; i < 1000; i++)
{
fx = f(a + i*h + h/2); // 求纵坐标;
sum = sum + fx*h; //微分法:面积相加
}
printf("%lf", sum);
}