The method of realizing the definite integral in C language _c language

Source: Internet
Author: User

In this paper, we illustrate the method of C language to achieve the definite integral. Share to everyone for your reference. The implementation methods are as follows:

Copy Code code as follows:

#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 ("Please select integrand: \ n"), printf ("1, exp (x) 2, x+1 \ n"), scanf ("%c", &selection), Selection!= ' # ') {
printf ("Please enter the lower limit of the points:");
scanf ("%f,%f", &up,&down);

Switch (selection) {
Case ' 1 ':
printf ("Result:%4.4f\n", Solve (FUN_EXP,UP,DOWN,ACC));
Break
Case ' 2 ':
printf ("Result:%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) {//unary two-time equation quadratics
return x+1;
}

I hope this article will help you with the C language program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.