Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <math.h>
- using namespace std;
- double f(double x) {
- return sqrt(2 * x + 1);
- }
- double gaussianQuad(double *nodes, double *weights, double a, double b, int n) {
- double res = 0;
- for (int i = 0; i < n; i++) res += f((b + a) / 2 + (b - a) / 2 * nodes[i]) * weights[i];
- res *= (b - a) / 2;
- return res;
- }
- int main() {
- ofstream fout;
- ifstream fin;
- fin.open("input.txt");
- fout.open("output.txt");
- int n;
- double a, b;
- fin >> a >> b;
- fin >> n;
- double *nodes = new double[n], *weights = new double[n];
- for (int i = 0; i < n; i++) fin >> weights[i] >> nodes[i];
- fout << setprecision(10) << gaussianQuad(nodes, weights, a, b, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement